From fa0928c1fdcbfd5a6eaa7d805a708697709ea118 Mon Sep 17 00:00:00 2001 From: Lawrence Daniels Date: Sun, 12 Feb 2017 14:12:39 -0800 Subject: [PATCH] Added a new callback to promise-with-error conversion --- .../main/scala/io/scalajs/util/PromiseHelper.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/src/main/scala/io/scalajs/util/PromiseHelper.scala b/core/src/main/scala/io/scalajs/util/PromiseHelper.scala index df6a020ac..c326424e4 100644 --- a/core/src/main/scala/io/scalajs/util/PromiseHelper.scala +++ b/core/src/main/scala/io/scalajs/util/PromiseHelper.scala @@ -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