Skip to content

Commit fa0928c

Browse files
committed
Added a new callback to promise-with-error conversion
1 parent 5b50eb4 commit fa0928c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

core/src/main/scala/io/scalajs/util/PromiseHelper.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ object PromiseHelper {
8383
task
8484
}
8585

86+
/**
87+
* Converts a JavaScript-style callback to a Scala.js promise
88+
* @param f the given callback function
89+
* @return a Scala.js promise
90+
*/
91+
@inline
92+
def promiseWithError0[Z](f: js.Function1[Z, Any] => Unit): Promise[Unit] = {
93+
val task = Promise[Unit]()
94+
f((err: Z) =>
95+
if (err == null || js.isUndefined(err)) task.success({}) else task.failure(wrapJavaScriptException(err)))
96+
task
97+
}
98+
8699
/**
87100
* Converts a JavaScript-style callback to a Scala.js promise
88101
* @param f the given callback function

0 commit comments

Comments
 (0)