How to use throat - 10 common examples

To help you get started, we’ve selected a few throat 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 facebook-atom / jest-electron-runner / packages / nuclide-e2e / src / TestRunner.js View on Github external
cleanup();
      process.exit(130);
    });
    process.on('uncaughtException', error => {
      // eslint-disable-next-line no-console
      console.error(error);
      cleanup();
      // This will prevent other handlers to handle errors
      // (e.g. global Jest handler). TODO: find a way to provide
      // a cleanup function to Jest so it runs it instead
      process.exit(1);
    });

    await Promise.all(
      tests.map(
        throat(concurrency, async test => {
          const config = test.context.config;
          const globalConfig = this._globalConfig;
          const {
            atomExecutable,
            consoleFilter,
            testTeardown,
            retries,
          } = findConfig(config.rootDir);
          let retriesLeft = retries || 1;
          let allRunResults = [];

          try {
            onStart(test);

            while (retriesLeft) {
              retriesLeft -= 1;
github patternplate / patternplate / packages / server / source / application / tasks / build-commonjs / index.js View on Github external
const pruned = await pruning;
  application.log.debug(
    ready`Pruned ${pruned.length} artifact files ${pruneStart}`
  );

  spinner.text = `${pruned.length}/${artifactsToPrune.length} pruned`;
  spinner.succeed();
  spinner.stop();

  spinner = ora().start();

  // Build patterns in parallel
  const buildStart = new Date();
  const building = Promise.all(
    patternsToBuild.map(
      throat(1, async pattern => {
        const filterStart = new Date();
        application.log.debug(
          wait`Checking for files of ${pattern.id} to exclude from transform.`
        );
        let changedFiles = [];

        // Enhance filters config to build only files that are modified
        const artifact = find(artifactMtimes, { id: pattern.id });

        if (artifact) {
          // Build up mtime registry for pattern files
          const filesMtimes = pattern.files.reduce((results, file, index) => {
            return { ...results, [file]: pattern.mtimes[index] };
          }, {});

          // Build up registry for artifact files
github jgornick / asyncp / src / rejectLimit.js View on Github external
export default promised(function rejectLimit(collection, limit, predicate) {
    if (! limit > 0) {
        return Promise.reject(new Error('Limit must be a number greater than 0.'));
    }

    return Promise.all(collection.map(throat(limit, (item, index, collection) =>
        tryFn(predicate, item, index, collection)
            .then(result => result === true ? ASYNCP_UNDEFINED : item)
    )))
        .then(results => results.filter(item => item != ASYNCP_UNDEFINED));
});
github jgornick / asyncp / src / eachOfLimit.js View on Github external
export default promised(function eachOfLimit(collection, limit, iteratee) {
    if (! limit > 0) {
        return Promise.reject(new Error('Limit must be a number greater than 0.'));
    }

    const keys = Object.keys(collection);
    const values = keys.map(key => collection[key]);
    return Promise.all(
        keys.map(throat(limit, (key, index) => {
            return tryFn(iteratee, values[index], key, collection)
        }))
    )
        .then((results) => results.reduce(
            (result, item, index) => {
                result[keys[index]] = item;
                return result;
            },
            {}
        ));
});
github jgornick / asyncp / src / timesLimit.js View on Github external
export default promised(function timesLimit(n, limit, iteratee, ...args) {
    return Promise.all(
        new Array(n)
            .fill()
            .map(throat(limit, (item, index) => tryFn(iteratee, index, ...args)))
    );
});
github jgornick / asyncp / src / eachLimit.js View on Github external
export default promised(function eachLimit(collection, limit, iteratee) {
    if (! limit > 0) {
        return Promise.reject(new Error('Limit must be a number greater than 0.'));
    }

    return Promise.all(collection.map(throat(limit, iteratee)));
});
github pedromsilvapt / unicast / src / Server / Providers / Youtube / YoutubeCaptionsOld.js View on Github external
downloadMultiple ( videos, options ) {
		return Promise.all( videos.map( throat( this.concurrency, ( video ) => {
			return this.download( video, options ).catch( reason => {
				if ( options.ignoreMissing ) {
					return null;
				}

				return Promise.reject( reason );
			} );
		} ) ) );
	}
}
github pedromsilvapt / unicast / src / Server / Providers / Youtube / SubtitlesDownloader.js View on Github external
downloadMultiple ( videos, options ) {
		return Promise.all( videos.map( throat( this.concurrency, ( video ) => {
			return this.download( video, options ).catch( reason => {
				if ( options.ignoreMissing ) {
					return null;
				}

				return Promise.reject( reason );
			} );
		} ) ) );
	}
}
github patternplate / patternplate / source / application / tasks / build-interface / get-pattern-datasets.js View on Github external
.then(patterns => {
				const idPad = padEnd(max(patterns.map(p => p.id.length)));

				const jobs = patterns.map(throat(1, async pattern => {
					observer.next({
						message: `${idPad(pattern.id)} ${count}/${patterns.length}`
					});
					const data = await getPatternMetaData(server, pattern.id, 'index');

					merge(data, pattern, {
						variants: {},
						environmentNames: data.environments.map(env => env.name)
					});

					count += 1;
					observer.next({data});
					return data;
				}));

				return Promise.all(jobs)
github pedromsilvapt / unicast / src / Server / Providers / Youtube / SubtitlesDownloader.js View on Github external
import sanitize from 'sanitize-filename';
import { spawn } from 'child_process';
import Download from 'download';
import config from 'config';
import throat from 'throat';
import langs from 'langs';
import Xray from 'x-ray';
import path from 'path';
import got from 'got';
import Qs from 'qs';
import is from 'is';

throat( Promise );

export default class SubtitlesDownloader {

	constructor ( concurrency = 5 ) {
		this.concurrency = concurrency;
		this.serverUrl = config.get( 'providers.youtube.captions.url' );
		this.middlewarePath = config.get( 'providers.youtube.captions.middleware.path' );
	}

	process ( subtitles ) {
		return new Promise( ( resolve, reject ) => {
			let node = spawn( 'node', [ '--harmony', path.basename( this.middlewarePath ), '"1"', '-s', '-p', '-r', config.get( 'providers.youtube.captions.middleware.rule' ) ], {
				cwd: path.dirname( this.middlewarePath )
			} );

			node.stdin.setEncoding( 'utf-8' );

throat

Throttle the parallelism of an asynchronous (promise returning) function / functions

MIT
Latest version published 2 years ago

Package Health Score

71 / 100
Full package analysis

Popular throat functions