Skip to content

Instantly share code, notes, and snippets.

@nashysolutions
nashysolutions / SingleTaskButton.swift
Last active February 14, 2026 12:11
Prevents user button smashing.
/// A button that ensures only a single async task executes at a time.
///
/// `SingleTaskButton` prevents double-execution of async operations by tracking the active task
/// and disabling itself while the operation is in progress. This is essential for critical
/// operations like purchases, payments, or irreversible actions where duplicate execution
/// would be harmful.
///
/// ## Example
/// ```swift
/// SingleTaskButton {