map.apps Bundle APIs 4.20.0
    Preparing search index...

    Function when

    • Helper to create stable code if a value can be a promise or a non async value.

      Type Parameters

      • Value
      • Result
      • Scope extends {}

      Parameters

      • Optionalvalue: Value | PromiseLike<Value>

        value or promise

      • Optionalsuccess: SuccessCallback<Value, Result, Scope>

        success callback

      • Optionalerror: ErrorCallback<Scope>

        error callback

      • Optionalscope: Scope

        this binding for the callbacks

      Returns ExtendedPromise<Result>

      always produces a promise

      // use it as wrapper to get a promise
      return when(thing).then((thing)=> doSomethingWithTheThing);
      import when from "apprt-core/when";
      // bind success and error handler from an object
      const 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.

      Type Parameters

      • Value
      • Result
      • Scope extends {}

      Parameters

      Returns ExtendedPromise<Result>