TKMAsync
public class TKMAsync
Undocumented
-
Creates a completed promise that resolves to the given value.
Declaration
Swift
public static func promiseFromResult<T>(_ result: T?) -> TKMPromise<T>
Parameters
result
the value the promise resolves to.
Return Value
a promise that is completed and resolves to the given value.
-
Creates a failed promise, that resolves to the given error.
Declaration
Swift
public static func promiseFromError<T>(_ e: Error) -> TKMPromise<T>
Parameters
e
the error the promise resolves to.
Return Value
a promise that is in a failed state and resolves to the given error.
-
Creates a completed promise that resolves to the given
TKMAsyncResult
.Declaration
Swift
public static func promiseFromAsyncResult<T>(_ asyncResult: (T?, Error?)) -> TKMPromise<T>
Parameters
asyncResult
the result the promise resolves to.
Return Value
a promise that is completed and resolves to the given result.
-
Runs the specified operation on a multi-threaded worker-thread-backed scheduler. If the specified operation completes successfully, the returned
TKMPromise<T>
resolves to the returned value. Otherwise it will resolve to the raisedError
.Declaration
Swift
public static func executeAsync<T>(_ f: @escaping () throws -> T?) -> TKMPromise<T>
Parameters
f
async operation to run.
Return Value
TKMPromise<T>
that continues on the caller’s currentTKMAsyncScheduler
with the operation’s result. -
Executes the specified function on the specified scheduler and returns a promise which will deliver the result on the caller’s current
TKMAsyncScheduler
.Declaration
Swift
public static func executeOnScheduler<T>(scheduler: TKMAsyncScheduler, _ f: @escaping () throws -> T?) -> TKMPromise<T>
Parameters
scheduler
scheduler to run the given operation on.
f
operation to run.
Return Value
TKMPromise<T>
that continues on the caller’s currentTKMAsyncScheduler
with the operation’s result. -
Returns a
TKMPromise<T>
that completes after the given time span.Declaration
Swift
public static func delayAsync(delayMs: Int64) -> TKMPromise<Void>
Parameters
delayMs
the number of milliseconds to delay.
Return Value
a
TKMPromise<T>
that completes after the given time span. -
Returns a
TKMPromise<T>
that completes after either the given time span elapsed or the givenTKMCancellationToken
requested cancellation. In the first case, the returnedTKMPromise<T>
completes successfully while in the second case it completes exceptionally with anTKMRuntimeError.cancellationError
.Declaration
Swift
public static func delayAsync(delayMs: Int64, cancellationToken: TKMCancellationToken) -> TKMPromise<Void>
Parameters
delayMs
the number of milliseconds to delay.
cancellationToken
the
TKMCancellationToken
that can be used for cancellation.Return Value
a
TKMPromise<T>
that completes either after the given time span elapsed or after cancellation, whatever happens earlier. -
Returns a completed
TKMPromise<T>
that resolves to null.Declaration
Swift
public static func first() -> TKMPromise<Void>
Return Value
a completed
TKMPromise<T>
that resolves to null. -
Synchronously executes the given
TKMAction
and then returns a completedTKMPromise<T>
that resolves to null. If execution of the action fails, the returned promise completes exceptionally and resolves to the raisedError
.Declaration
Swift
public static func first(_ action: @escaping () throws -> Void) -> TKMPromise<Void>
Parameters
action
the action to execute.
Return Value
a completed
TKMPromise<T>
that resolves according to the outcome of the specified action. -
Synchronously executes the given
TKMFunc
and then returns a completedTKMPromise<T>
that resolves to the value returned by the function. If execution fails, the returned promise completes exceptionally and resolves to the raisedError
.Declaration
Swift
public static func first<T>(_ fn: @escaping () throws -> T?) -> TKMPromise<T>
Parameters
fn
the function to execute.
Return Value
a completed
TKMPromise<T>
that resolves according to the outcome of the specified function. -
Starts an async function on the specified scheduler and continues the returned promise on the caller’s current scheduler.
Declaration
Swift
public static func switchToScheduler<T>(scheduler: TKMAsyncScheduler, _ f: @escaping () -> TKMPromise<T>) -> TKMPromise<T>
Parameters
scheduler
Scheduler to start the specified async operation on.
f
Async operation to be started on the specified scheduler.
Return Value
Promise that continues on the caller’s current scheduler.
-
Starts an async function on the specified scheduler and continues the returned promise on the other specified scheduler.
Declaration
Swift
public static func switchToScheduler<T>(runOnScheduler: TKMAsyncScheduler, continueOnScheduler: TKMAsyncScheduler, _ f: @escaping () -> TKMPromise<T> ) -> TKMPromise<T>
Parameters
runOnScheduler
Scheduler to start the specified async operation on.
continueOnScheduler
Scheduler to continue the returned promise on.
f
Async operation to be started on the specified scheduler.
Return Value
Promise that continues on the specified scheduler.