deno.land / x / rambda@v9.1.1 / source / ifElseAsync.js

ifElseAsync.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function createThenable(fn){ return async function (...input){ return fn(...input) }}
export function ifElseAsync( condition, ifFn, elseFn){ return (...inputs) => new Promise((resolve, reject) => { const conditionPromise = createThenable(condition) const ifFnPromise = createThenable(ifFn) const elseFnPromise = createThenable(elseFn)
conditionPromise(...inputs) .then(conditionResult => { const promised = conditionResult === true ? ifFnPromise : elseFnPromise
promised(...inputs) .then(resolve) .catch(reject) }) .catch(reject) })}
rambda

Version Info

Tagged at
2 months ago