-module(gleam@javascript@promise). -compile(no_auto_import). -export([resolve/1, rescue/2, then/2, map/2, tap/2, map_try/2, then_try/2, await2/2, await3/3, await4/4, await5/5, await6/6, await_array/1, await_list/1]). -export_type([promise/1]). -type promise(Value) :: any() | {gleam_phantom, Value}. -spec resolve(EOI) -> promise(EOI). resolve(Field@0) -> '../../ffi.mjs':resolve(Field@0). -spec rescue(promise(EOK), fun((gleam@dynamic:dynamic()) -> EOK)) -> promise(EOK). rescue(Field@0, Field@1) -> '../../ffi.mjs':rescue(Field@0, Field@1). -spec then(promise(EOP), fun((EOP) -> promise(EON))) -> promise(EON). then(Field@0, Field@1) -> '../../ffi.mjs':then(Field@0, Field@1). -spec map(promise(EOU), fun((EOU) -> EOS)) -> promise(EOS). map(Field@0, Field@1) -> '../../ffi.mjs':map_promise(Field@0, Field@1). -spec tap(promise(EOW), fun((EOW) -> any())) -> promise(EOW). tap(Promise, Callback) -> _pipe = Promise, '../../ffi.mjs':map_promise( _pipe, fun(A) -> Callback(A), A end ). -spec map_try( promise({ok, EPA} | {error, EPB}), fun((EPA) -> {ok, EPF} | {error, EPB}) ) -> promise({ok, EPF} | {error, EPB}). map_try(Promise, Callback) -> _pipe = Promise, '../../ffi.mjs':map_promise(_pipe, fun(Result) -> case Result of {ok, A} -> Callback(A); {error, E} -> {error, E} end end). -spec then_try( promise({ok, EPL} | {error, EPM}), fun((EPL) -> promise({ok, EPQ} | {error, EPM})) ) -> promise({ok, EPQ} | {error, EPM}). then_try(Promise, Callback) -> _pipe = Promise, '../../ffi.mjs':then(_pipe, fun(Result) -> case Result of {ok, A} -> Callback(A); {error, E} -> '../../ffi.mjs':resolve({error, E}) end end). -spec await2(promise(EPX), promise(EPY)) -> promise({EPX, EPY}). await2(Field@0, Field@1) -> '../../ffi.mjs':all_promises(Field@0, Field@1). -spec await3(promise(EQC), promise(EQD), promise(EQE)) -> promise({EQC, EQD, EQE}). await3(Field@0, Field@1, Field@2) -> '../../ffi.mjs':all_promises(Field@0, Field@1, Field@2). -spec await4(promise(EQJ), promise(EQK), promise(EQL), promise(EQM)) -> promise({EQJ, EQK, EQL, EQM}). await4(Field@0, Field@1, Field@2, Field@3) -> '../../ffi.mjs':all_promises(Field@0, Field@1, Field@2, Field@3). -spec await5( promise(EQS), promise(EQT), promise(EQU), promise(EQV), promise(EQW) ) -> promise({EQS, EQT, EQU, EQV, EQW}). await5(Field@0, Field@1, Field@2, Field@3, Field@4) -> '../../ffi.mjs':all_promises(Field@0, Field@1, Field@2, Field@3, Field@4). -spec await6( promise(ERD), promise(ERE), promise(ERF), promise(ERG), promise(ERH), promise(ERI) ) -> promise({ERD, ERE, ERF, ERG, ERH, ERI}). await6(Field@0, Field@1, Field@2, Field@3, Field@4, Field@5) -> '../../ffi.mjs':all_promises(Field@0, Field@1, Field@2, Field@3, Field@4, Field@5). -spec await_array(gleam@javascript@array:array(promise(ERQ))) -> promise(gleam@javascript@array:array(ERQ)). await_array(Field@0) -> '../../ffi.mjs':all_promises(Field@0). -spec await_list(list(promise(ERV))) -> promise(list(ERV)). await_list(Xs) -> _pipe = Xs, _pipe@1 = '../../ffi.mjs':all_promises(_pipe), '../../ffi.mjs':map_promise(_pipe@1, fun gleam@javascript@array:to_list/1).