diff --git a/gulpfile.js b/gulpfile.js index 597141b6d4..36b5833023 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,7 +1,8 @@ 'use strict' const gulp = require('gulp') -const async = require('async') +const parallel = require('run-parallel') +const series = require('run-series') const createTempNode = require('./test/utils/temp-node') const API = require('./src/http-api') @@ -18,7 +19,7 @@ function startNode (num, done) { } gulp.task('libnode:start', (done) => { - async.parallel([ + parallel([ (cb) => startNode(7, cb), (cb) => startNode(8, cb), (cb) => startNode(9, cb) @@ -26,9 +27,9 @@ gulp.task('libnode:start', (done) => { }) gulp.task('libnode:stop', (done) => { - async.eachSeries(nodes, (node, cb) => { + series(nodes.map((node) => (cb) => { setTimeout(() => node.stop(cb), 500) - }, done) + }), done) }) gulp.task('test:browser:before', ['libnode:start']) diff --git a/package.json b/package.json index d711f79b3e..afcb210858 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "homepage": "https://github.com/ipfs/js-ipfs#readme", "devDependencies": { "aegir": "^3.0.1", - "async": "^2.0.0-rc.4", "buffer-loader": "0.0.1", "chai": "^3.5.0", "expose-loader": "^0.7.1", @@ -84,6 +83,10 @@ "peer-info": "^0.6.2", "readable-stream": "1.1.13", "ronin": "^0.3.11", + "run-parallel": "^1.1.6", + "run-parallel-limit": "^1.0.3", + "run-series": "^1.1.4", + "run-waterfall": "^1.1.3", "temp": "^0.8.3" }, "aegir": { diff --git a/src/cli/commands/config/edit.js b/src/cli/commands/config/edit.js index 5bcfde40cc..b510f1e640 100644 --- a/src/cli/commands/config/edit.js +++ b/src/cli/commands/config/edit.js @@ -4,7 +4,7 @@ const Command = require('ronin').Command const spawn = require('child_process').spawn const fs = require('fs') const temp = require('temp') -const async = require('async') +const waterfall = require('run-waterfall') const debug = require('debug') const log = debug('cli:config') log.error = debug('cli:config:error') @@ -99,7 +99,7 @@ module.exports = Command.extend({ }) } - async.waterfall([ + waterfall([ getConfig, saveTempConfig, openEditor, diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index 080ed22be3..f69a8b700f 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -7,7 +7,7 @@ const log = debug('cli:version') log.error = debug('cli:version:error') const bs58 = require('bs58') const fs = require('fs') -const async = require('async') +const parallelLimit = require('run-parallel-limit') const path = require('path') const glob = require('glob') @@ -69,7 +69,7 @@ module.exports = Command.extend({ }) if (res.length !== 0) { const index = inPath.lastIndexOf('/') - async.eachLimit(res, 10, (element, callback) => { + parallelLimit(res.map((element) => (callback) => { if (!fs.statSync(element).isDirectory()) { i.write({ path: element.substring(index + 1, element.length), @@ -77,7 +77,7 @@ module.exports = Command.extend({ }) } callback() - }, (err) => { + }), 10, (err) => { if (err) { throw err } diff --git a/src/core/ipfs/go-online.js b/src/core/ipfs/go-online.js index 94d80b98fe..236359b466 100644 --- a/src/core/ipfs/go-online.js +++ b/src/core/ipfs/go-online.js @@ -1,11 +1,11 @@ 'use strict' -const async = require('async') +const series = require('run-series') const Bitswap = require('ipfs-bitswap') module.exports = function goOnline (self) { return (cb) => { - async.series([ + series([ self.load, self.libp2p.start ], (err) => { diff --git a/src/core/ipfs/init.js b/src/core/ipfs/init.js index 2c108ccf83..e0a020919e 100644 --- a/src/core/ipfs/init.js +++ b/src/core/ipfs/init.js @@ -5,7 +5,7 @@ const BlockService = require('ipfs-block-service') const DagService = require('ipfs-merkle-dag').DAGService const path = require('path') const glob = require('glob') -const async = require('async') +const parallelLimit = require('run-parallel-limit') const Readable = require('stream').Readable const fs = require('fs') const Importer = require('ipfs-unixfs-engine').importer @@ -85,7 +85,7 @@ module.exports = function init (self) { throw err } const index = __dirname.lastIndexOf('/') - async.eachLimit(res, 10, (element, callback) => { + parallelLimit(res.map((element) => (callback) => { const addPath = element.substring(index + 1, element.length) if (!fs.statSync(element).isDirectory()) { const rs = new Readable() @@ -95,7 +95,7 @@ module.exports = function init (self) { i.write(filePair) } callback() - }, (err) => { + }), 10, (err) => { if (err) { throw err } diff --git a/src/http-api/index.js b/src/http-api/index.js index ce233654d8..b9b5c98b9a 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -1,6 +1,6 @@ 'use strict' -const async = require('async') +const parallel = require('run-parallel') const Hapi = require('hapi') const debug = require('debug') const fs = require('fs') @@ -95,7 +95,7 @@ exports = module.exports = function HttpApi (repo) { console.log('Stopping server') - async.parallel([ + parallel([ (cb) => this.server.stop(cb), (cb) => this.ipfs.goOffline(cb) ], (err) => { diff --git a/test/core-tests/browser.js b/test/core-tests/browser.js index cd9b91b9e9..52a62e1368 100644 --- a/test/core-tests/browser.js +++ b/test/core-tests/browser.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ 'use strict' -const async = require('async') +const series = require('run-series') const store = require('idb-plus-blob-store') const _ = require('lodash') @@ -29,7 +29,7 @@ describe('IPFS Repo Tests on the Browser', function () { const mainBlob = store('ipfs') const blocksBlob = store('ipfs/blocks') - async.eachSeries(repoData, (file, cb) => { + series(repoData.map((file) => (cb) => { if (_.startsWith(file.key, 'datastore/')) { return cb() } @@ -41,7 +41,7 @@ describe('IPFS Repo Tests on the Browser', function () { blob.createWriteStream({ key: key }).end(file.value, cb) - }, done) + }), done) }) it('--', () => { diff --git a/test/core-tests/test-bitswap.js b/test/core-tests/test-bitswap.js index 381463be30..1fed64ec25 100644 --- a/test/core-tests/test-bitswap.js +++ b/test/core-tests/test-bitswap.js @@ -3,7 +3,9 @@ const expect = require('chai').expect const _ = require('lodash') -const async = require('async') +const series = require('run-series') +const waterfall = require('run-waterfall') +const parallel = require('run-parallel') const Block = require('ipfs-block') const bs58 = require('bs58') const bl = require('bl') @@ -16,7 +18,7 @@ function makeBlock () { return new Block(`IPFS is awesome ${Math.random()}`) } -describe('bitswap', () => { +describe.only('bitswap', () => { let ipfs beforeEach((done) => { @@ -43,7 +45,7 @@ describe('bitswap', () => { } function connectNodes (node1, node2, done) { - async.series([ + series([ (cb) => connectNodesSingle(node1, node2, cb), (cb) => setTimeout(() => { // need timeout so we wait for identify to happen @@ -74,7 +76,7 @@ describe('bitswap', () => { it('2 peers', (done) => { const block = makeBlock() let node - async.series([ + series([ // 0. Start node (cb) => addNode(9, (err, _ipfs) => { node = _ipfs @@ -97,7 +99,7 @@ describe('bitswap', () => { const blocks = _.range(6).map((i) => makeBlock()) const keys = blocks.map((b) => b.key) const nodes = [] - async.series([ + series([ (cb) => addNode(8, (err, _ipfs) => { nodes.push(_ipfs) cb(err) @@ -114,7 +116,7 @@ describe('bitswap', () => { (cb) => ipfs.block.put(blocks[4], cb), (cb) => ipfs.block.put(blocks[5], cb), // 3. Fetch blocks on all nodes - (cb) => async.each(_.range(6), (i, cbI) => { + (cb) => parallel(_.range(6).map((i) => (cbI) => { const toMh = (k) => bs58.encode(k).toString() const check = (n, k, callback) => { n.block.get(k, (err, b) => { @@ -128,12 +130,12 @@ describe('bitswap', () => { }) } - async.series([ + series([ (cbJ) => check(nodes[0], toMh(keys[i]), cbJ), (cbJ) => check(nodes[1], toMh(keys[i]), cbJ), (cbJ) => check(ipfs, keys[i], cbJ) ], cbI) - }, cb) + }), cb) ], done) }) }) @@ -148,7 +150,7 @@ describe('bitswap', () => { const file = new Buffer('I love IPFS <3') let node - async.waterfall([ + waterfall([ // 0. Start node (cb) => addNode(9, (err, _ipfs) => { node = _ipfs