-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
183 changed files
with
315 additions
and
40,396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Sources/Operations/AsynchronousCancellableBlockOperation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// AdvancedOperation | ||
|
||
public typealias AsyncCancellableBlockOperation = AsynchronousCancellableBlockOperation | ||
|
||
/// A sublcass of `AsynchronousOperation` to execute a cancellable closure. | ||
/// - Note: If the operation gets cancelled before being executed, the block won't be called. | ||
/// | ||
/// This operation let you run a block until *complete* is called; its cancelled state is exposed during the whole execution. | ||
/// ``` | ||
/// let operation = AsyncCancellableBlockOperation { isCancelled, complete in | ||
/// // work ... | ||
/// if isCancelled() { | ||
/// complete() | ||
/// return | ||
/// } | ||
/// // work ... | ||
/// complete() | ||
/// } | ||
public final class AsynchronousCancellableBlockOperation: AsynchronousOperation, @unchecked Sendable { | ||
// MARK: - Private Properties | ||
|
||
private var block: (@escaping @Sendable () -> Bool, @escaping @Sendable () -> Void) -> Void | ||
|
||
// MARK: - Initializers | ||
|
||
/// The designated initializer. | ||
/// | ||
/// - Parameters: | ||
/// - block: The closure to run when the operation executes; the parameter passed to the block **MUST** be invoked by your code, | ||
/// or else the `AsynchronousBlockOperation` will never finish executing. | ||
public init(block: @Sendable @escaping (@escaping @Sendable () -> Bool, @escaping @Sendable () -> Void) -> Void) { | ||
self.block = block | ||
super.init() | ||
self.name = "\(type(of: self))" | ||
} | ||
|
||
// MARK: - Overrides | ||
|
||
public final override func main() { | ||
guard !isCancelled else { | ||
self.finish() | ||
return | ||
} | ||
|
||
block ({ | ||
self.isCancelled | ||
}) { | ||
self.finish() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.