aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/javascript/promise.gleam13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/gleam/javascript/promise.gleam b/src/gleam/javascript/promise.gleam
index 7e3670a..8407c8c 100644
--- a/src/gleam/javascript/promise.gleam
+++ b/src/gleam/javascript/promise.gleam
@@ -31,3 +31,16 @@ pub fn map_try(
}
})
}
+
+pub fn then_try(
+ promise: Promise(Result(a, e)),
+ callback: fn(a) -> Promise(Result(b, e)),
+) -> Promise(Result(b, e)) {
+ promise
+ |> then(fn(result) {
+ case result {
+ Ok(a) -> callback(a)
+ Error(e) -> resolve(Error(e))
+ }
+ })
+}