How to use the promise.resolve function in promise

To help you get started, we’ve selected a few promise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github recurly / recurly-js / lib / recurly / pricing / checkout / calculations.js View on Github external
discounts () {
    const coupon = this.items.coupon;
    let promise = Promise.resolve();

    this.price.now.discount = 0;
    this.price.next.discount = 0;

    // Remove all previously-applied coupons
    this.validSubscriptions.forEach(sub => {
      promise = promise.then(() => sub.coupon().reprice(null, { internal: true }));
    });

    if (!coupon) return promise;

    if (coupon.discount.type === 'free_trial') {
      promise = promise.then(() => this.applyFreeTrialCoupon());
    } else {
      const { discountNow, discountNext } = this.discountAmounts();
      this.price.now.discount = discountNow;
github facebook / metro / react-packager / src / DependencyResolver / DependencyGraph / ResolutionRequest.js View on Github external
}).then(([depNames, dependencies]) => {
          let p = Promise.resolve();
          const filteredPairs = [];

          dependencies.forEach((modDep, i) => {
            const name = depNames[i];
            if (modDep == null) {
              // It is possible to require mocks that don't have a real
              // module backing them. If a dependency cannot be found but there
              // exists a mock with the desired ID, resolve it and add it as
              // a dependency.
              if (allMocks && allMocks[name] && !mocks[name]) {
                const mockModule = this._moduleCache.getModule(allMocks[name]);
                mocks[name] = allMocks[name];
                return filteredPairs.push([name, mockModule]);
              }

              debug(
github facebook / regenerator / test / async.js View on Github external
async function h(arg) {
        return await Promise.all([
          g(arg),
          Promise.resolve("dummy")
        ]);
      }
github skivvyjs / skivvy / test / fixtures / mockNpmCommandsFactory.js View on Github external
update: sinon.spy(function(packages, options, projectPath, callback) {
			return Promise.resolve('1.2.4').nodeify(callback);
		}),
		reset: function() {
github ReactiveX / rxjs / spec / operators / concatMapTo-spec.js View on Github external
it('should concatMapTo values to resolved promises with resultSelector', function (done) {
    var source = Rx.Observable.from([4,3,2,1]);
    var resultSelectorCalledWith = [];
    var inner = Observable.from(Promise.resolve(42));
    var resultSelector = function (outerVal, innerVal, outerIndex, innerIndex) {
      resultSelectorCalledWith.push([].slice.call(arguments));
      return 8;
    };

    var results = [];
    var expectedCalls = [
      [4, 42, 0, 0],
      [3, 42, 1, 0],
      [2, 42, 2, 0],
      [1, 42, 3, 0]
    ];
    source.concatMapTo(inner, resultSelector).subscribe(
      function next(x) {
        results.push(x);
      },
github decred / decrediton / app / wallet / daemon.js View on Github external
export const stopDaemon = log(() => Promise
  .resolve(ipcRenderer.sendSync("stop-daemon"))
  .then(stopped => {
    return stopped;
  }), "Stop Daemon");
github bicyclejs / bicycle / src / runner / run-mutation.js View on Github external
}).then(value => {
    if (method && method.type) {
      return Promise.resolve(
        validateMutationReturnType(schema, logging, method.type, value),
      ).then(value => {
        return {s: true, v: value};
      });
    } else {
      return true;
    }
  });
}
github madhusudhand / angular2-cli / lib / tasks / base / npm-task.js View on Github external
npmInstall() {
    return Promise.resolve(
      npm(this.command, [], {}, this.options).
      then(this.errorLog.bind(this))
    ).
    finally(this.finally.bind(this)).
    then(this.announceCompletion.bind(this)).
    catch(this.announceFailure.bind(this));
  }
github MiEcosystem / ios-rn-sdk / MiHomePluginSDK / node_modules / react-native / packager / react-packager / src / Bundler / index.js View on Github external
.then(transformedModules =>
          Promise.resolve(
            finalizeBundle({bundle, transformedModules, response, modulesByName})
          ).then(() => bundle)
        );
github mkay581 / router-component / src / router.ts View on Github external
triggerRoute (url, options) {
        options = options || {};
        options.triggerUrlChange = typeof options.triggerUrlChange !== 'undefined' ? options.triggerUrlChange : true;
        if (url !== this._currentPath) {
            return this._onRouteRequest(url, options);
        } else {
            return Promise.resolve();
        }
    }