How to use is-generator-fn - 2 common examples

To help you get started, we’ve selected a few is-generator-fn 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 dora-js / dora / src / plugin.js View on Github external
}, {});
    // Add more context api
    contextModify.plugins = plugins;
    contextModify.query = plugin.query;
    contextModify.log = log;
    contextModify.callback = callback;
    contextModify.restart = () => {
      console.log();
      spmLog.info('dora', 'try to restart...');
      process.send('restart');
    };

    if (name === 'middleware') {
      contextModify.app.use(func.call(contextModify));
      callback();
    } else if (isGeneratorFn(func)) {
      co.wrap(func).call(contextModify).then((val) => {
        callback(null, val);
      }, callback);
    } else {
      const funcResult = func.call(contextModify, memo);
      if (funcResult && funcResult.then) {
        funcResult
        .then(result => {
          callback(null, result);
        })
        .catch(callback)
        .catch(err => {
          throw new Error(err);
        });
      } else {
        callback(null, funcResult);
github facebook / jest / packages / jest-circus / src / utils.ts View on Github external
if (completed && reason) {
          errorAsErrorObject.message =
            'Caught error after test environment was torn down\n\n' +
            errorAsErrorObject.message;

          throw errorAsErrorObject;
        }

        return reason ? reject(errorAsErrorObject) : resolve();
      };

      return fn.call(testContext, done);
    }

    let returnedValue;
    if (isGeneratorFn(fn)) {
      returnedValue = co.wrap(fn).call({});
    } else {
      try {
        returnedValue = fn.call(testContext);
      } catch (error) {
        return reject(error);
      }
    }

    // If it's a Promise, return it. Test for an object with a `then` function
    // to support custom Promise implementations.
    if (
      typeof returnedValue === 'object' &&
      returnedValue !== null &&
      typeof returnedValue.then === 'function'
    ) {

is-generator-fn

Check if something is a generator function

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis

Popular is-generator-fn functions