Helper to create stable code if a value can be a promise or a non async value.
Optional
value or promise
success callback
error callback
this binding for the callbacks
always produces a promise
// use it as wrapper to get a promisereturn when(thing).then((thing)=> doSomethingWithTheThing); Copy
// use it as wrapper to get a promisereturn when(thing).then((thing)=> doSomethingWithTheThing);
import when from "apprt-core/when";// bind success and error handler from an objectconst scope = { counter : 0, ok() { ++this.counter; }, error() { --this.counter; }};return when(thing, scope.ok, scope.error, scope); Copy
import when from "apprt-core/when";// bind success and error handler from an objectconst scope = { counter : 0, ok() { ++this.counter; }, error() { --this.counter; }};return when(thing, scope.ok, scope.error, scope);
Same as the first overload, but without an error callback.
Helper to create stable code if a value can be a promise or a non async value.