Protocols
The following protocols are available globally.
-
A protocol that defines how to execute a task.
This protocol has extension methods that allow to launch coroutines on a current scheduler. Inside the coroutine you can use such methods as
Coroutine.await(_:)
,CoFuture.await()
, andCoroutineScheduler.await(_:)
to suspend the coroutine without blocking a thread and resume it when the result is ready.The framework includes the implementation of this protocol for
DispatchQueue
and you can easily make the same for other schedulers as well.
See moreextension OperationQueue: CoroutineScheduler { public func scheduleTask(_ task: @escaping () -> Void) { addOperation(task) } }
Declaration
Swift
public protocol CoroutineScheduler