How to use promise-queue - 10 common examples

To help you get started, we’ve selected a few promise-queue 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 ALiangLiang / Counter-for-Messenger / src / tab / lib / fetchService.js View on Github external
/// ///////////////////////////////////////////////////////////////////////////////
// A service to send request to API. Controll request flow to avoid become DDOS. //
/// ///////////////////////////////////////////////////////////////////////////////
import Queue from 'promise-queue'
const queue = new Queue(40, Infinity)

// Used to debug. How much fetch mission queue. How much fetch mission pending.
// setInterval(() => console.log(queue.getQueueLength(), queue.getPendingLength()), 3000)

export default async function fetchService (...args) {
  return new Promise((resolve, reject) => {
    let wrapper = null
    try {
      wrapper = async () => {
        try {
          const response = await fetch(...args)
          if (!response.ok) throw new Error('No ok.')
          return resolve(response)
        } catch (err) {
          console.error(err)
          return reject(err)
github clay / clay-kiln / lib / core-data / queue.js View on Github external
import Queue from 'promise-queue';
import store from './store';
import { START_PROGRESS, FINISH_PROGRESS } from '../toolbar/mutationTypes';

const maxConcurrency = 1,
  maxQueue = Infinity,
  queue = new Queue(maxConcurrency, maxQueue),
  queueCache = {}; // make sure we don't do the same api call over and over if it takes too long

/**
 * get number of queued and pending pending promises
 * @return {number}
 */
function getPendingCount() {
  return queue.queue.length + queue.pendingPromises;
}

/**
 * see if a queue has anything pendingPromises
 * @return {Boolean}
 */
export function isPending() {
  return getPendingCount() > 0;
github dbcls / sparql-proxy / src / tracker.js View on Github external
constructor() {
    super();

    this.jobs = {}; // TODO cleanup old jobs
    this.queue = new Queue(1, Infinity); // TODO make the parameters configurable
  }
github ALiangLiang / Counter-for-Messenger / src / tab / lib / util.js View on Github external
import Queue from 'promise-queue'

const _queue = new Queue(40, Infinity)
let reqCounter = 1

// http get
export function get (url) {
  return fetchService(url, {
    credentials: 'same-origin'
  })
}

export function toQuerystring (form) {
  return Object.keys(form).map(function (key) {
    const val = (typeof form[key] === 'object')
      ? JSON.stringify(form[key]) : form[key]
    return encodeURIComponent(key) +
      ((form[key] !== undefined) ? ('=' + encodeURIComponent(val)) : '')
  }).join('&')
github robertklep / nefit-easy-core / lib / index.js View on Github external
'use strict';
const Promise    = require('bluebird');
const Queue      = require('promise-queue'); Queue.configure(Promise);
const debug      = require('debug')('nefit-easy-core');
const rawDebug   = require('debug')('nefit-easy-core:raw');
const HTTPParser = require('http-string-parser');
const XMPPClient = require('node-xmpp-client');
const Stanza     = XMPPClient.Stanza;
const Encryption = require('./encryption');
const SCRAM      = require('./scram-auth-mechanism');

// Default options for XMPP
const DEFAULT_OPTIONS = {
  host           : 'wa2-mz36-qrmzh6.bosch.de',
  saslMechanism  : 'SCRAM-SHA-1',
  pingInterval   : 30 * 1000,
  maxRetries     : 15,
  retryTimeout   : 2000,
};
github mattgodbolt / compiler-explorer / lib / compilation-env.js View on Github external
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

const
    Queue = require('promise-queue'),
    child_process = require('child_process'),
    FromConfig = require('./cache/from-config'),
    BaseCache = require('./cache/base'),
    logger = require('./logger').logger,
    _ = require('underscore'),
    fs = require('fs-extra'),
    Sentry = require('@sentry/node');

Queue.configure(Promise);

class CompilationEnvironment {
    constructor(compilerProps, doCache) {
        this.ceProps = compilerProps.ceProps;
        this.compilerProps = compilerProps.get.bind(compilerProps);
        this.okOptions = new RegExp(this.ceProps('optionsWhitelistRe', '.*'));
        this.badOptions = new RegExp(this.ceProps('optionsBlacklistRe', '(?!)'));
        this.cache = FromConfig.create(doCache === undefined || doCache ? this.ceProps('cacheConfig', '') : "");
        this.executableCache = FromConfig.create(
            doCache === undefined || doCache ? this.ceProps('executableCacheConfig', '') : "");
        this.compilerCache = FromConfig.create(
            doCache === undefined || doCache ? this.ceProps('compilerCacheConfig', '') : "");
        this.compileQueue = new Queue(this.ceProps("maxConcurrentCompiles", 1), Infinity);
        this.reportCacheEvery = this.ceProps("cacheReportEvery", 100);
        this.multiarch = null;
        try {
github serverless / serverless / lib / plugins / aws / provider / awsProvider.js View on Github external
const chalk = require('chalk');
const _ = require('lodash');
const userStats = require('../../../utils/userStats');
const naming = require('../lib/naming.js');
const https = require('https');
const fs = require('fs');
const objectHash = require('object-hash');
const PromiseQueue = require('promise-queue');
const getS3EndpointForRegion = require('../utils/getS3EndpointForRegion');
const readline = require('readline');

const constants = {
  providerName: 'aws',
};

PromiseQueue.configure(BbPromise.Promise);

const impl = {
  /**
   * Determine whether the given credentials are valid.  It turned out that detecting invalid
   * credentials was more difficult than detecting the positive cases we know about.  Hooray for
   * whak-a-mole!
   * @param credentials The credentials to test for validity
   * @return {boolean} Whether the given credentials were valid
   */
  validCredentials: credentials => {
    let result = false;
    if (credentials) {
      if (
        // valid credentials loaded
        (credentials.accessKeyId &&
          credentials.accessKeyId !== 'undefined' &&
github box / box-node-sdk / lib / util / paging-iterator.js View on Github external
* @callback IteratorCallback
 * @param {?Error} err - An error if the iterator encountered one
 * @param {IteratorData} [data] - New data from the iterator
 * @returns {void}
 */

// -----------------------------------------------------------------------------
// Requirements
// -----------------------------------------------------------------------------

var querystring = require('querystring'),
	Promise = require('bluebird'),
	PromiseQueue = require('promise-queue'),
	errors = require('./errors');

PromiseQueue.configure(Promise);

// -----------------------------------------------------------------------------
// Private
// -----------------------------------------------------------------------------

const PAGING_MODES = Object.freeze({
	MARKER: 'marker',
	OFFSET: 'offset'
});

// -----------------------------------------------------------------------------
// Public
// -----------------------------------------------------------------------------

/**
 * Asynchronous iterator for paged collections
github grafana / github-to-es / app.js View on Github external
var Queue = require('promise-queue');
var program = require('commander');
var RepoSync = require('./reposync');
var db = require('./db');

// set promise
Queue.configure(require('bluebird'));

var queue = new Queue(1, 1000);

function startRepoSync() {
  const config = require('./config.json');

  for (let repoSyncOptions of config.repos) {
    const rs = new RepoSync(repoSyncOptions, queue);
    rs.start();
  }
}

program
  .version('0.0.1')
  .command('start')
  .action(startRepoSync);
github inventid / gennie / index.js View on Github external
var Nightmare  = require('nightmare'),
    Promise    = require('bluebird'),
    Queue      = require('promise-queue'),
    express    = require('express'),
    bodyParser = require('body-parser'),
    uuid       = require('node-uuid'),
    fs         = require('fs'),
    config     = require('./config.json');

// Set promise-queue to use
// bluebird's promises.
Queue.configure(Promise);

var port        = process.env.PORT || config.port,
    timeout     = process.env.TIMEOUT || config.timeout,
    concurrency = process.env.CONCURRENCY || config.concurrency,
    nightmares  = Array(concurrency).fill().map(function() { return Nightmare(); }),
    queue       = new Queue(concurrency, Infinity),
    server      = express();

// Create the rendering engine for a new render call
function render(data) {
  var id        = uuid.v4(),
      output    = '/tmp/' + id + '.pdf',
      router    = express.Router(),
      nightmare = nightmares.pop(), // Get ourselves a nightmare worker
      deferred;

promise-queue

Promise-based queue

MIT
Latest version published 6 years ago

Package Health Score

65 / 100
Full package analysis

Similar packages