Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

refactor: replace async with light weight alternatives #20

Merged
merged 1 commit into from
May 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@
"chai": "^3.5.0",
"fs-blob-store": "^5.2.1",
"idb-plus-blob-store": "^1.1.2",
"ipfs-block": "^0.3.0",
"ipfs-repo": "^0.7.1",
"lodash": "^4.8.2",
"ncp": "^2.0.0",
"pre-commit": "^1.1.2",
"ipfs-block": "^0.3.0",
"rimraf": "^2.5.1"
"rimraf": "^2.5.1",
"run-series": "^1.1.4"
},
"dependencies": {
"async": "^1.5.2"
"run-parallel-limit": "^1.0.3"
},
"contributors": [
"David Dias <[email protected]>",
"Friedel Ziegelmayer <[email protected]>",
"Stephen Whitmore <[email protected]>"
]
}
}
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const async = require('async')
const parallelLimit = require('run-parallel-limit')

// BlockService is a hybrid block datastore. It stores data in a local
// datastore and may retrieve data from a remote Exchange.
Expand Down Expand Up @@ -41,9 +41,9 @@ module.exports = class BlockService {
return callback(new Error('expects an array of Blocks'))
}

async.eachLimit(blocks, 100, (block, next) => {
parallelLimit(blocks.map((block) => (next) => {
this.addBlock(block, next)
}, callback)
}), 100, callback)
}

getBlock (key, extension, callback) {
Expand Down Expand Up @@ -71,15 +71,15 @@ module.exports = class BlockService {

var results = {}

async.eachLimit(multihashes, 100, (multihash, next) => {
parallelLimit(multihashes.map((multihash) => (next) => {
this.getBlock(multihash, extension, (err, block) => {
results[multihash] = {
err: err,
block: block
}
next()
})
}, (err) => {
}), 100, (err) => {
callback(err, results)
})
}
Expand All @@ -98,9 +98,9 @@ module.exports = class BlockService {
return callback(new Error('Invalid batch of multihashes'))
}

async.eachLimit(multihashes, 100, (multihash, next) => {
parallelLimit(multihashes.map((multihash) => (next) => {
this.deleteBlock(multihash, extension, next)
}, (err) => {
}), 100, (err) => {
callback(err)
})
}
Expand Down
6 changes: 3 additions & 3 deletions test/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')
const IPFSRepo = require('ipfs-repo')
Expand Down Expand Up @@ -31,7 +31,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 @@ -44,7 +44,7 @@ describe('IPFS Repo Tests on the Browser', function () {
blob.createWriteStream({
key: key
}).end(file.value, cb)
}, done)
}), done)
})

const repo = new IPFSRepo('ipfs', {stores: store})
Expand Down