TKMPromiseSource
public class TKMPromiseSource<T>
Instances of this class are used to create and complete TKMPromise<T>
instances. Instances of
this class are produced with a reference to an TKMAsyncScheduler
, which is used to invoke
continuations on the returned TKMPromise<T>
. By default, the current scheduler is captured
when calling the constructor.
-
Creates an instance based on the current schedule as returned by AsyncSchedulers#current().
Declaration
Swift
public init()
-
Creates an instance based on the given scheduler.
Declaration
Swift
public init(scheduler: TKMAsyncScheduler)
Parameters
scheduler
-
Returns the
TKMPromise<T>
associated with this instance.Declaration
Swift
public var promise: TKMPromise<T> { get }
-
Returns whether this instance and the returned
TKMPromise<T>
are in completed state, regardless of whether completed successfully or exceptionally.Declaration
Swift
public func isCompleted() -> Bool
Return Value
whether this instance and the returned
TKMPromise<T>
are in completed state. -
Completes the
TKMPromise<T>
associated with this instance with the given value. throwsJavaLangIllegalStateException
if already in completed state.Declaration
Swift
public func setResult(_ result: T?)
Parameters
result
result the result value the associated
TKMPromise<T>
should be resolved to. -
Tries to complete the
TKMPromise<T>
associated with this instance with the given value. Ignores the given value if already in completed state.Declaration
Swift
public func trySetResult(_ result: T?) -> Bool
Parameters
result
the result value the associated
TKMPromise<T>
should be resolved to.Return Value
true if the
TKMPromise<T>
associated with this instance was completed successfully, false if already completed. -
Exceptionally completes the
TKMPromise<T>
associated with this instance with the givenError
. throwsJavaLangIllegalStateException
if already in completed state.Declaration
Swift
public func setError(_ e: Error)
Parameters
e
the
Error
the associatedTKMPromise<T>
should be resolved to. -
Tries to exceptionally complete the
TKMPromise<T>
associated with this instance with the givenError
. Ignores the given value if already in completed state.Declaration
Swift
public func trySetError(_ e: Error) -> Bool
Parameters
e
the
Error
the associatedTKMPromise<T>
should be resolved to.Return Value
true if the
TKMPromise<T>
associated with this instance was completed successfully, false if already completed.