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

Commit 5ab53e7

Browse files
committed
Merge pull request #20 from ipfs/no-async
refactor: replace async with light weight alternatives
2 parents 30e9f82 + 6f1a7bb commit 5ab53e7

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@
4343
"chai": "^3.5.0",
4444
"fs-blob-store": "^5.2.1",
4545
"idb-plus-blob-store": "^1.1.2",
46+
"ipfs-block": "^0.3.0",
4647
"ipfs-repo": "^0.7.1",
4748
"lodash": "^4.8.2",
4849
"ncp": "^2.0.0",
4950
"pre-commit": "^1.1.2",
50-
"ipfs-block": "^0.3.0",
51-
"rimraf": "^2.5.1"
51+
"rimraf": "^2.5.1",
52+
"run-series": "^1.1.4"
5253
},
5354
"dependencies": {
54-
"async": "^1.5.2"
55+
"run-parallel-limit": "^1.0.3"
5556
},
5657
"contributors": [
5758
"David Dias <[email protected]>",
5859
"Friedel Ziegelmayer <[email protected]>",
5960
"Stephen Whitmore <[email protected]>"
6061
]
61-
}
62+
}

src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

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

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

44-
async.eachLimit(blocks, 100, (block, next) => {
44+
parallelLimit(blocks.map((block) => (next) => {
4545
this.addBlock(block, next)
46-
}, callback)
46+
}), 100, callback)
4747
}
4848

4949
getBlock (key, extension, callback) {
@@ -71,15 +71,15 @@ module.exports = class BlockService {
7171

7272
var results = {}
7373

74-
async.eachLimit(multihashes, 100, (multihash, next) => {
74+
parallelLimit(multihashes.map((multihash) => (next) => {
7575
this.getBlock(multihash, extension, (err, block) => {
7676
results[multihash] = {
7777
err: err,
7878
block: block
7979
}
8080
next()
8181
})
82-
}, (err) => {
82+
}), 100, (err) => {
8383
callback(err, results)
8484
})
8585
}
@@ -98,9 +98,9 @@ module.exports = class BlockService {
9898
return callback(new Error('Invalid batch of multihashes'))
9999
}
100100

101-
async.eachLimit(multihashes, 100, (multihash, next) => {
101+
parallelLimit(multihashes.map((multihash) => (next) => {
102102
this.deleteBlock(multihash, extension, next)
103-
}, (err) => {
103+
}), 100, (err) => {
104104
callback(err)
105105
})
106106
}

test/browser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const async = require('async')
4+
const series = require('run-series')
55
const store = require('idb-plus-blob-store')
66
const _ = require('lodash')
77
const IPFSRepo = require('ipfs-repo')
@@ -31,7 +31,7 @@ describe('IPFS Repo Tests on the Browser', function () {
3131
const mainBlob = store('ipfs')
3232
const blocksBlob = store('ipfs/blocks')
3333

34-
async.eachSeries(repoData, (file, cb) => {
34+
series(repoData.map((file) => (cb) => {
3535
if (_.startsWith(file.key, 'datastore/')) {
3636
return cb()
3737
}
@@ -44,7 +44,7 @@ describe('IPFS Repo Tests on the Browser', function () {
4444
blob.createWriteStream({
4545
key: key
4646
}).end(file.value, cb)
47-
}, done)
47+
}), done)
4848
})
4949

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

0 commit comments

Comments
 (0)