// Zero-cost type conversion
let js_val : @core.Any = @core.any(moonbit_value)
let back : MyType = js_val.cast()
// Property access
js_val["key"] = @core.any(value)
let prop = js_val["key"]
// Method call
let result = js_val._call("method", [@core.any(arg1), @core.any(arg2)])#external
pub type Any#external
pub type Nullable[T]#external
pub type Nullish[T]#external
pub type Promise[T]let results = Promise::all([
Promise::from_async(async fn() { fetch_user() }),
Promise::from_async(async fn() { fetch_posts() }),
]).wait()let results = Promise::allSettled([
Promise::from_async(async fn() { 1 }),
Promise::from_async(async fn() { fail("error") }),
]).wait()
// results[0].status == "fulfilled", results[0].value == Some(1)
// results[1].status == "rejected", results[1].reason != nulllet first_success = Promise::any([
Promise::from_async(async fn() { fetch_from_mirror1() }),
Promise::from_async(async fn() { fetch_from_mirror2() }),
]).wait()let p : Promise[Int] = Promise::from_async(async fn() {
let result = some_async_operation()
result
})let p : Promise[Int] = Promise::new(async fn(resolve, _reject) {
let result = some_async_operation()
resolve(result)
})let first = Promise::race([
Promise::from_async(async fn() {
sleep(100)
"slow"
}),
Promise::from_async(async fn() {
sleep(10)
"fast"
}),
]).wait() // "fast"pub(all) struct PromiseResolvers[T] {
promise : Promise[T]
resolve : (T) -> Unit
reject : (Error) -> Unit
}#external
pub type Union2[A, B]#external
pub type Union3[A, B, C]#external
pub type Union4[A, B, C, D]#external
pub type Union5[A, B, C, D, E]async fn[T, E : Error] suspend(f : ((T) -> Unit, (E) -> Unit) -> Unit) -> T raise EInstall
Download zipbindings for js/node/browser/deno/cloudflare/react etc