diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ffi.js | 4 | ||||
-rw-r--r-- | src/gleam/javascript/promise.gleam | 5 |
2 files changed, 9 insertions, 0 deletions
@@ -94,3 +94,7 @@ export function map_promise(promise, fn) { PromiseLayer.wrap(fn(PromiseLayer.unwrap(value))) ); } + +export function rescue(promise, fn) { + return promise.catch((error) => fn(error)); +} diff --git a/src/gleam/javascript/promise.gleam b/src/gleam/javascript/promise.gleam index 8407c8c..3c7190c 100644 --- a/src/gleam/javascript/promise.gleam +++ b/src/gleam/javascript/promise.gleam @@ -1,3 +1,5 @@ +import gleam/dynamic.{Dynamic} + // TODO: docs // TODO: labels pub external type Promise(value) @@ -5,6 +7,9 @@ pub external type Promise(value) pub external fn resolve(value) -> Promise(value) = "../../ffi.js" "resolve" +pub external fn rescue(Promise(value), fn(Dynamic) -> value) -> Promise(value) = + "../../ffi.js" "rescue" + pub external fn then(Promise(a), fn(a) -> Promise(b)) -> Promise(b) = "../../ffi.js" "then" |