Skip to content

Commit

Permalink
Added a new callback to promise-with-error conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ldaniels528 committed Feb 12, 2017
1 parent 5b50eb4 commit fa0928c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/src/main/scala/io/scalajs/util/PromiseHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ object PromiseHelper {
task
}

/**
* Converts a JavaScript-style callback to a Scala.js promise
* @param f the given callback function
* @return a Scala.js promise
*/
@inline
def promiseWithError0[Z](f: js.Function1[Z, Any] => Unit): Promise[Unit] = {
val task = Promise[Unit]()
f((err: Z) =>
if (err == null || js.isUndefined(err)) task.success({}) else task.failure(wrapJavaScriptException(err)))
task
}

/**
* Converts a JavaScript-style callback to a Scala.js promise
* @param f the given callback function
Expand Down

0 comments on commit fa0928c

Please sign in to comment.