Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
refactor: replace async with light weight modules
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 11, 2016
1 parent 1adef97 commit 255f6d1
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 29 deletions.
9 changes: 5 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -18,17 +19,17 @@ function startNode (num, done) {
}

gulp.task('libnode:start', (done) => {
async.parallel([
parallel([
(cb) => startNode(7, cb),
(cb) => startNode(8, cb),
(cb) => startNode(9, cb)
], 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'])
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/config/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -99,7 +99,7 @@ module.exports = Command.extend({
})
}

async.waterfall([
waterfall([
getConfig,
saveTempConfig,
openEditor,
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/files/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -69,15 +69,15 @@ 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),
stream: fs.createReadStream(element)
})
}
callback()
}, (err) => {
}), 10, (err) => {
if (err) {
throw err
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/ipfs/go-online.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/core/ipfs/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -95,7 +95,7 @@ module.exports = function init (self) {
i.write(filePair)
}
callback()
}, (err) => {
}), 10, (err) => {
if (err) {
throw err
}
Expand Down
4 changes: 2 additions & 2 deletions src/http-api/index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions test/core-tests/browser.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down Expand Up @@ -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()
}
Expand All @@ -41,7 +41,7 @@ describe('IPFS Repo Tests on the Browser', function () {
blob.createWriteStream({
key: key
}).end(file.value, cb)
}, done)
}), done)
})

it('--', () => {
Expand Down
20 changes: 11 additions & 9 deletions test/core-tests/test-bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -16,7 +18,7 @@ function makeBlock () {
return new Block(`IPFS is awesome ${Math.random()}`)
}

describe('bitswap', () => {
describe.only('bitswap', () => {
let ipfs

beforeEach((done) => {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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) => {
Expand All @@ -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)
})
})
Expand All @@ -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
Expand Down

0 comments on commit 255f6d1

Please sign in to comment.