aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter <peterhsaxton@gmail.com>2023-08-03 19:37:35 +0200
committerLouis Pilfold <louis@lpil.uk>2023-08-09 13:47:02 +0100
commit69593662f47e5c797cc8076d72d70ac24d3813f7 (patch)
treea392d83de37aa1ee417616957efa65162448c2b3 /src
parenta093f74fe70ae34ac0573b3b2ab715a51432d546 (diff)
downloadjavascript-69593662f47e5c797cc8076d72d70ac24d3813f7.tar.gz
javascript-69593662f47e5c797cc8076d72d70ac24d3813f7.zip
new format of external functions for new promise
Diffstat (limited to 'src')
-rw-r--r--src/ffi.mjs8
-rw-r--r--src/gleam/javascript/promise.gleam3
2 files changed, 11 insertions, 0 deletions
diff --git a/src/ffi.mjs b/src/ffi.mjs
index 4aa6995..3889aa8 100644
--- a/src/ffi.mjs
+++ b/src/ffi.mjs
@@ -81,6 +81,14 @@ class PromiseLayer {
}
}
+export function newPromise(executor) {
+ return Promise.resolve((resolve) =>
+ executor((value) => {
+ resolve(PromiseLayer.wrap(value));
+ })
+ );
+}
+
export function resolve(value) {
return Promise.resolve(PromiseLayer.wrap(value));
}
diff --git a/src/gleam/javascript/promise.gleam b/src/gleam/javascript/promise.gleam
index 8d531eb..db8a7ef 100644
--- a/src/gleam/javascript/promise.gleam
+++ b/src/gleam/javascript/promise.gleam
@@ -5,6 +5,9 @@ import gleam/javascript/array.{Array}
// TODO: labels
pub type Promise(value)
+@external(javascript, "../../ffi.mjs", "newPromise")
+pub fn new(a: fn(fn(value) -> Nil) -> Nil) -> Promise(value)
+
@external(javascript, "../../ffi.mjs", "resolve")
pub fn resolve(a: value) -> Promise(value)