How to use the promise.prototype.finally 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 ember-cli / ember-cli / lib / tasks / server / middleware / tests-server / index.js View on Github external
if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
            // N.B., `baseURL` will end with a slash as it went through `cleanBaseURL`
            let newURL = `${baseURL}tests/index.html`;

            logger.info(
              'url: %s resolved to path: %s which is not a file. Assuming %s instead',
              req.path,
              filePath,
              newURL
            );
            req.url = newURL;
          }
        }
      });

      promiseFinally(promiseFinally(Promise.resolve(results), next), () => {
        if (config.finally) {
          config.finally();
        }
      });
    });
  }
github broccolijs / broccoli / lib / watcher.ts View on Github external
_quit() {
    logger.debug('quitStart');
    this.emit('quitStart');

    this._quittingPromise = promiseFinally(
      promiseFinally(Promise.resolve().then(() => this.watcherAdapter.quit()), () => {
        // Wait for current build, and ignore build failure
        return Promise.resolve(this.currentBuild).catch(() => {});
      }),
      () => {
        logger.debug('quitEnd');
        this.emit('quitEnd');
      }
    );

    return this._quittingPromise;
  }
};
github broccolijs / broccoli / lib / builder.ts View on Github external
promise = promise.then(() => {
        let needsEndNode = false;
        // We use a nested .then/.catch so that the .catch can only catch errors
        // from this node, but not from previous nodes.
        return promiseFinally(
          Promise.resolve()
            .then(() => this._cancelationRequest.throwIfRequested())
            .then(() => {
              this.emit('beginNode', nw);
              needsEndNode = true;
            })
            .then(() => nw.build()),
          () => {
            if (needsEndNode) {
              this.emit('endNode', nw);
            }
          }
        )
          .then(() => this._cancelationRequest.throwIfRequested())
          .catch(err => {
            if (Cancelation.isCancelationError(err)) {
github ember-cli / ember-cli / tests / acceptance / smoke-test-slow.js View on Github external
it('ember build generates instrumentation files when viz is enabled', co.wrap(function *() {
    process.env.BROCCOLI_VIZ = '1';

    yield promiseFinally(runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build', {
      env: {
        BROCCOLI_VIZ: '1',
      },
    }), () => delete process.env.BROCCOLI_VIZ);

    [
      'instrumentation.build.0.json',
      'instrumentation.command.json',
      'instrumentation.init.json',
      'instrumentation.shutdown.json',
    ].forEach(instrumentationFile => {
      expect(fs.existsSync(instrumentationFile)).to.equal(true);

      let json = fs.readJsonSync(instrumentationFile);
      expect(Object.keys(json)).to.eql([
        'summary', 'nodes',
github broccolijs / broccoli / lib / cli.ts View on Github external
watcher.quit();
        }
      });
      watcher.on('buildFailure', (err: any) => {
        ui.writeLine('build failure', 'ERROR');
        ui.writeError(err);
      });

      function cleanupAndExit() {
        return watcher.quit();
      }

      process.on('SIGINT', cleanupAndExit);
      process.on('SIGTERM', cleanupAndExit);

      actionPromise = promiseFinally(watcher.start().catch((err: any) => ui.writeError(err)), () => {
        builder.cleanup();
        process.exit(0);
      }).catch((err: any) => {
        ui.writeLine('Cleanup error:', 'ERROR');
        ui.writeError(err);
        process.exit(1);
      });
    });
github siphomateke / huawei-router-api / src / utils.js View on Github external
_runItem(idx) {
    promiseFinally(this.list[idx](), () => {
      this._onComplete();
    });
  }
  /**
github ember-cli / ember-cli / lib / tasks / npm-task.js View on Github external
let ui = this.ui;
      let startMessage = this.formatStartMessage(options.packages);
      let completeMessage = this.formatCompleteMessage(options.packages);

      ui.startProgress(chalk.green(startMessage));

      let promise;
      if (this.useYarn) {
        let args = this.toYarnArgs(this.command, options);
        promise = this.yarn(args);
      } else {
        let args = this.toNpmArgs(this.command, options);
        promise = this.npm(args);
      }

      return promiseFinally(promise, () => ui.stopProgress())
        .then(() => ui.writeLine(chalk.green(completeMessage)));
    });
  }
github ember-cli / ember-cli / lib / models / blueprint.js View on Github external
this.hasPathToken = hasPathToken(this.files());

    ui.writeLine(`installing ${this.name}`);

    if (dryRun) {
      ui.writeLine(chalk.yellow('You specified the dry-run flag, so no' +
        ' changes will be written.'));
    }

    this._normalizeEntityName(options.entity);
    this._checkForPod(options.verbose);
    this._checkInRepoAddonExists(options.inRepoAddon);

    logger.info('START: processing blueprint: `%s`', this.name);
    let start = new Date();
    return promiseFinally(this._process(options, this.beforeInstall, this.processFiles, this.afterInstall),
      () => logger.info('END: processing blueprint: `%s` in (%dms)', this.name, new Date() - start));
  },
github broccolijs / broccoli / lib / builder.ts View on Github external
cleanup() {
    return promiseFinally(this.cancel(), () => this.builderTmpDirCleanup());
  }