How to use d3-queue - 10 common examples

To help you get started, we’ve selected a few d3-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 DefinitelyTyped / DefinitelyTyped / d3-queue / d3-queue-tests.ts View on Github external
if (error) throw error;
    console.log('Goodbye!');
});

// Task with Reuslts -------------------------------------------------

// await
qWithResults
    .await(function (error, file1Stat, file2Stat) {
        if (error) throw error;
        console.log(file1Stat, file2Stat);
    });

// awaitAll

qWithResults = d3Queue.queue()
    .defer(getFileStats, './workingpath/file1.json')
    .defer(getFileStats, './yetanotherworkingpath/file2.json')
    .awaitAll(function (error, fileStats) {
        if (error) throw error;
            console.log(fileStats[0], fileStats[1]);
    });


// Abort Deferred Tasks ==============================================

function requestDataFromInterWeb(url: string, callback: (error: any | null, data?: any) => void) {
    // magically get data from the interweb, e.g. like d3-request would, while supporting an abort() method
}

qWithResults = d3Queue.queue()
    .defer(requestDataFromInterWeb, 'http://www.google.com:81')
github DefinitelyTyped / DefinitelyTyped / types / d3-queue / d3-queue-tests.ts View on Github external
if (error) throw error;
    console.log('Goodbye!');
});

// Task with Reuslts -------------------------------------------------

// await
qWithResults
    .await((error, file1Stat, file2Stat) => {
        if (error) throw error;
        console.log(file1Stat, file2Stat);
    });

// awaitAll

qWithResults = d3Queue.queue()
    .defer(getFileStats, './workingpath/file1.json')
    .defer(getFileStats, './yetanotherworkingpath/file2.json')
    .awaitAll((error, fileStats) => {
        if (error) throw error;
        console.log(fileStats[0], fileStats[1]);
    });

// Abort Deferred Tasks ==============================================

function requestDataFromInterWeb(url: string, callback: (error: any | null, data?: any) => void) {
    // magically get data from the interweb, e.g. like d3-request would, while supporting an abort() method
}

qWithResults = d3Queue.queue()
    .defer(requestDataFromInterWeb, 'http://www.google.com:81')
    .defer(requestDataFromInterWeb, 'http://www.google.com:81')
github DefinitelyTyped / DefinitelyTyped / d3-queue / d3-queue-tests.ts View on Github external
* are not intended as functional tests.
 */

import * as d3Queue from 'd3-queue';

// -------------------------------------------------------------------
// Test Queue
// -------------------------------------------------------------------

// Create queue ======================================================

let qNoResult: d3Queue.Queue;
let qWithResults: d3Queue.Queue;

// With default concurrency
qNoResult = d3Queue.queue();

// With limited concurrency
qWithResults = d3Queue.queue(3);

// Defer Tasks =======================================================

// No Results Task ---------------------------------------------------

function delayedHello(name: string, delay: number, callback: (error: any | null) => void) {
    setTimeout(function () {
        console.log('Hello, ' + name + '!');
        callback(null);
    }, delay);
}
github DefinitelyTyped / DefinitelyTyped / types / d3-queue / d3-queue-tests.ts View on Github external
* are not intended as functional tests.
 */

import * as d3Queue from 'd3-queue';

// -------------------------------------------------------------------
// Test Queue
// -------------------------------------------------------------------

// Create queue ======================================================

let qNoResult: d3Queue.Queue;
let qWithResults: d3Queue.Queue;

// With default concurrency
qNoResult = d3Queue.queue();

// With limited concurrency
qWithResults = d3Queue.queue(3);

// Defer Tasks =======================================================

// No Results Task ---------------------------------------------------

function delayedHello(name: string, delay: number, callback: (error: any | null) => void) {
    setTimeout(() => {
        console.log('Hello, ' + name + '!');
        callback(null);
    }, delay);
}

qNoResult = qNoResult.defer(delayedHello, 'Alice', 250);
github mhkeller / indian-ocean / lib / index.js View on Github external
readers.readDbf = function (filePath, opts_, cb) {
  var parserOptions = {
    map: function (d) { return d }
  }
  if (typeof cb === 'undefined') {
    cb = opts_
  } else {
    parserOptions = _.isFunction(opts_) ? {map: opts_} : opts_
  }
  var reader = shapefileDbf.reader(filePath)
  var rows = []
  var headers

  // Run these in order
  queue(1)
    .defer(readHeader)
    .defer(readAllRecords)
    .defer(close)
    .await(function (error, readHeaderData, readAllRecordsData, jsonData) {
      // We're using queue to work through this flow
      // As a result, `readHeaderData`, `readAllRecordsData` are going to be undefined
      // Because they aren't meant to return anything, just process data
      // `rowData`, however contains all our concatenated data, so let's return that
      cb(error, jsonData)
    })

  function readHeader (callback) {
    reader.readHeader(function (error, header) {
      if (error) {
        return callback(error)
      }
github Project-OSRM / osrm-backend / features / support / cache.js View on Github external
];

        var addLuaFiles = (directory, callback) => {
            fs.readdir(path.normalize(directory), (err, files) => {
                if (err) return callback(err);

                var luaFiles = files.filter(f => !!f.match(/\.lua$/)).map(f => path.normalize(directory + '/' + f));
                Array.prototype.push.apply(dependencies, luaFiles);

                callback();
            });
        };

        // Note: we need a serialized queue here to ensure that the order of the files
        // passed is stable. Otherwise the hash will not be stable
        d3.queue(1)
            .defer(addLuaFiles, this.PROFILES_PATH)
            .defer(addLuaFiles, this.PROFILES_PATH + '/lib')
            .awaitAll(hash.hashOfFiles.bind(hash, dependencies, callback));
    };
github Project-OSRM / osrm-backend / features / step_definitions / routability.js View on Github external
// use the mode of the first step of the route
                        // for routability table test, we can assume the mode is the same throughout the route,
                        // since the route is just a single way
                        if( r.json.routes[0].legs[0] && r.json.routes[0].legs[0].steps[0] ) {
                            r.mode = r.json.routes[0].legs[0].steps[0].mode;
                        }
                    } else {
                        r.status = null;
                    }
                }

                callback(null, r);
            });
        };

        d3.queue(1)
            .defer(testDirection, 'forw')
            .defer(testDirection, 'backw')
            .awaitAll((err, res) => {
                if (err) return cb(err);
                // check if forw and backw returned the same values
                res.forEach((dirRes) => {
                    var which = dirRes.which;
                    delete dirRes.which;
                    result[which] = dirRes;
                });

                result.bothw = {};

                var sq = d3.queue();

                var parseRes = (key, scb) => {
github Project-OSRM / osrm-backend / features / support / data.js View on Github external
this.extractContractPartitionAndCustomize = (callback) => {
        // a shallow copy of scenario parameters to avoid data inconsistency
        // if a cucumber timeout occurs during deferred jobs
        let p = {extractArgs: this.extractArgs, contractArgs: this.contractArgs,
            partitionArgs: this.partitionArgs, customizeArgs: this.customizeArgs,
            profileFile: this.profileFile, inputCacheFile: this.inputCacheFile,
            processedCacheFile: this.processedCacheFile, environment: this.environment};
        let queue = d3.queue(1);
        queue.defer(this.extractData.bind(this), p);
        queue.defer(this.partitionData.bind(this), p);
        queue.defer(this.contractData.bind(this), p);
        queue.defer(this.customizeData.bind(this), p);
        queue.awaitAll(callback);
    };
github mapbox / kine / test / utils.js View on Github external
module.exports.init = function (t) {
  const q = queue(1);
  q.defer(dynalite.listen.bind(dynalite), 4568);
  q.defer(kinesalite.listen.bind(kinesalite), 5568);
  q.defer(kinesisClient.createStream.bind(kinesisClient), {
    ShardCount: process.env.shardCount || 2,
    StreamName: config.streamName
  });
  q.await((err) => {
    if (err && err.code != 'ResourceInUseException') t.fail(err.stack);
    console.log(`Dynalite started on port 4568, Kinesalite started on port 5568, created stream ${config.streamName}`);
    t.end();
  });
};

d3-queue

Evaluate asynchronous tasks with configurable concurrency.

BSD-3-Clause
Latest version published 7 years ago

Package Health Score

53 / 100
Full package analysis

Popular d3-queue functions