Result
The result of a promise.
enum Result
The result of a promise.
enum Result
import JavaScriptKit
final class JSPromise
A wrapper around the JavaScript Promise
class
case success(JSValue)
The promise resolved with a value.
case failure(JSValue)
The promise rejected with a value.
convenience init?(_ jsObject: JSObject)
Creates a new JSPromise
instance from a given JavaScript Promise
object. If jsObject
is not an instance of JavaScript Promise
, this initializer will return nil
.
convenience init(resolver: @escaping (@escaping (Result) -> Void) -> Void)
Creates a new JSPromise
instance from a given resolver
closure. The closure is passed a completion handler. Passing a successful Result
to the completion handler will cause the promise to resolve with the corresponding value; passing a failure Result
will cause the promise to reject with the corresponding value. Calling the completion handler more than once will have no effect (per the JavaScript specification).
init(unsafelyWrapping object: JSObject)
This private initializer assumes that the passed object is a JavaScript Promise
static var constructor: JSFunction? { get }
static func construct(from value: JSValue) -> Self?
Creates a new JSPromise
instance from a given JavaScript Promise
object. If value
is not an object and is not an instance of JavaScript Promise
, this function will return nil
.
static func reject(_ reason: ConvertibleToJSValue) -> JSPromise
static func resolve(_ value: ConvertibleToJSValue) -> JSPromise
let jsObject: JSObject
The underlying JavaScript Promise
object.
@discardableResult func `catch`(failure: sending @escaping (sending JSValue) async throws -> ConvertibleToJSValue) -> JSPromise
Schedules the failure
closure to be invoked on rejected completion of self
.
@discardableResult func `catch`(failure: @escaping (sending JSValue) -> ConvertibleToJSValue) -> JSPromise
Schedules the failure
closure to be invoked on rejected completion of self
.
@discardableResult func finally(successOrFailure: @escaping () -> Void) -> JSPromise
Schedules the failure
closure to be invoked on either successful or rejected completion of self
.
func jsValue() -> JSValue
The underlying JavaScript Promise
object wrapped as JSValue
.
@discardableResult func then(success: @escaping (JSValue) -> ConvertibleToJSValue) -> JSPromise
Schedules the success
closure to be invoked on successful completion of self
.
@discardableResult func then(success: sending @escaping (sending JSValue) async throws -> ConvertibleToJSValue) -> JSPromise
Schedules the success
closure to be invoked on successful completion of self
.
@discardableResult func then(success: sending @escaping (sending JSValue) async throws -> ConvertibleToJSValue, failure: sending @escaping (sending JSValue) async throws -> ConvertibleToJSValue) -> JSPromise
Schedules the success
closure to be invoked on successful completion of self
.
@discardableResult func then(success: @escaping (sending JSValue) -> ConvertibleToJSValue, failure: @escaping (sending JSValue) -> ConvertibleToJSValue) -> JSPromise
Schedules the success
closure to be invoked on successful completion of self
.
protocol Equatable
A type that can be compared for value equality.
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.