Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cc3ee05

Browse files
billatnpmisaacs
authored andcommittedSep 15, 2019
feat(promise): removed .map, replaced with p-map. removed .try
1 parent 478f5cb commit cc3ee05

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed
 

Diff for: ‎lib/content/read.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const ReadOpts = figgyPudding({
1818
})
1919

2020
module.exports = read
21+
2122
function read (cache, integrity, opts) {
2223
opts = ReadOpts(opts)
2324
return withContentSri(cache, integrity, (cpath, sri) => {
@@ -34,6 +35,7 @@ function read (cache, integrity, opts) {
3435
}
3536

3637
module.exports.sync = readSync
38+
3739
function readSync (cache, integrity, opts) {
3840
opts = ReadOpts(opts)
3941
return withContentSriSync(cache, integrity, (cpath, sri) => {
@@ -50,6 +52,7 @@ function readSync (cache, integrity, opts) {
5052

5153
module.exports.stream = readStream
5254
module.exports.readStream = readStream
55+
5356
function readStream (cache, integrity, opts) {
5457
opts = ReadOpts(opts)
5558
const stream = new PassThrough()
@@ -92,6 +95,7 @@ function copySync (cache, integrity, dest, opts) {
9295
}
9396

9497
module.exports.hasContent = hasContent
98+
9599
function hasContent (cache, integrity) {
96100
if (!integrity) { return BB.resolve(false) }
97101
return withContentSri(cache, integrity, (cpath, sri) => {
@@ -109,6 +113,7 @@ function hasContent (cache, integrity) {
109113
}
110114

111115
module.exports.hasContent.sync = hasContentSync
116+
112117
function hasContentSync (cache, integrity) {
113118
if (!integrity) { return false }
114119
return withContentSriSync(cache, integrity, (cpath, sri) => {
@@ -129,12 +134,13 @@ function hasContentSync (cache, integrity) {
129134
}
130135

131136
function withContentSri (cache, integrity, fn) {
132-
return BB.try(() => {
137+
const tryFn = () => {
133138
const sri = ssri.parse(integrity)
134139
// If `integrity` has multiple entries, pick the first digest
135140
// with available local data.
136141
const algo = sri.pickAlgorithm()
137142
const digests = sri[algo]
143+
138144
if (digests.length <= 1) {
139145
const cpath = contentPath(cache, digests[0])
140146
return fn(cpath, digests[0])
@@ -153,6 +159,14 @@ function withContentSri (cache, integrity, fn) {
153159
}
154160
})
155161
}
162+
}
163+
164+
return new Promise((resolve, reject) => {
165+
try {
166+
tryFn().then(resolve).catch(reject)
167+
} catch (err) {
168+
reject(err)
169+
}
156170
})
157171
}
158172

Diff for: ‎lib/verify.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const BB = require('bluebird')
44

5+
const pMap = require('p-map')
56
const contentPath = require('./content/path')
67
const figgyPudding = require('figgy-pudding')
78
const finished = BB.promisify(require('mississippi').finished)
@@ -111,7 +112,7 @@ function garbageCollect (cache, opts) {
111112
reclaimedSize: 0,
112113
badContentCount: 0,
113114
keptSize: 0
114-
}).then((stats) => BB.map(files, (f) => {
115+
}).then((stats) => pMap(files, (f) => {
115116
const split = f.split(/[/\\]/)
116117
const digest = split.slice(split.length - 3).join('')
117118
const algo = split[split.length - 4]
@@ -195,7 +196,7 @@ function rebuildIndex (cache, opts) {
195196
}
196197
}
197198
}
198-
return BB.map(Object.keys(buckets), key => {
199+
return pMap(Object.keys(buckets), key => {
199200
return rebuildBucket(cache, buckets[key], stats, opts)
200201
}, { concurrency: opts.concurrency }).then(() => stats)
201202
})

Diff for: ‎package-lock.json

+23-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"mississippi": "^3.0.0",
6969
"mkdirp": "^0.5.1",
7070
"move-concurrently": "^1.0.1",
71+
"p-map": "^3.0.0",
7172
"promise-inflight": "^1.0.1",
7273
"rimraf": "^2.6.3",
7374
"ssri": "^6.0.1",

0 commit comments

Comments
 (0)
Failed to load comments.