Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jed Fox <git@jedfox.com>
  • Loading branch information
kateinoigakukun and j-f1 authored Jan 6, 2021
1 parent 58ca905 commit a85ee3f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Sources/JavaScriptKit/BasicObjects/JSPromise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class JSPromise: JSBridgedClass {
/** Creates a new `JSPromise` instance from a given `resolver` closure. `resolver` takes
two closure that your code should call to either resolve or reject this `JSPromise` instance.
*/
public convenience init(resolver: @escaping (@escaping (Result<JSValue, JSValue>) -> ()) -> ()) {
public convenience init(resolver: @escaping (@escaping (Result< JSValueConvertible, JSValueConvertible >) -> ()) -> ()) {
let closure = JSOneshotClosure { arguments in
// The arguments are always coming from the `Promise` constructor, so we should be
// safe to assume their type here
Expand All @@ -66,18 +66,18 @@ public final class JSPromise: JSBridgedClass {
self.init(unsafelyWrapping: Self.constructor.new(closure))
}

public static func resolve(_ value: JSValue) -> JSPromise {
public static func resolve(_ value: JSValueConvertible) -> JSPromise {
self.init(unsafelyWrapping: Self.constructor.resolve!(value).object!)
}

public static func reject(_ reason: JSValue) -> JSPromise {
public static func reject(_ reason: JSValueConvertible) -> JSPromise {
self.init(unsafelyWrapping: Self.constructor.reject!(reason).object!)
}

/** Schedules the `success` closure to be invoked on sucessful completion of `self`.
*/
@discardableResult
public func then(success: @escaping (JSValue) -> JSValue) -> JSPromise {
public func then(success: @escaping (JSValue) -> JSValueConvertible) -> JSPromise {
let closure = JSOneshotClosure {
return success($0[0])
}
Expand All @@ -87,8 +87,8 @@ public final class JSPromise: JSBridgedClass {
/** Schedules the `success` closure to be invoked on sucessful completion of `self`.
*/
@discardableResult
public func then(success: @escaping (JSValue) -> JSValue,
failure: @escaping (JSValue) -> JSValue) -> JSPromise {
public func then(success: @escaping (JSValue) -> JSValueConvertible,
failure: @escaping (JSValue) -> JSValueConvertible) -> JSPromise {
let successClosure = JSOneshotClosure {
return success($0[0])
}
Expand All @@ -101,7 +101,7 @@ public final class JSPromise: JSBridgedClass {
/** Schedules the `failure` closure to be invoked on rejected completion of `self`.
*/
@discardableResult
public func `catch`(failure: @escaping (JSValue) -> JSValue) -> JSPromise {
public func `catch`(failure: @escaping (JSValue) -> JSValueConvertible) -> JSPromise {
let closure = JSOneshotClosure {
return failure($0[0])
}
Expand Down

0 comments on commit a85ee3f

Please sign in to comment.