Skip to content

Commit c21298c

Browse files
billatnpmisaacs
authored andcommitted
feat(promise): removed bluebird
1 parent 220c56d commit c21298c

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

lib/content/read.js

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

3-
const BB = require('bluebird')
43
const util = require('util')
54

65
const contentPath = require('./path')
@@ -146,19 +145,36 @@ function withContentSri (cache, integrity, fn) {
146145
const cpath = contentPath(cache, digests[0])
147146
return fn(cpath, digests[0])
148147
} else {
149-
return BB.any(sri[sri.pickAlgorithm()].map(meta => {
150-
return withContentSri(cache, meta, fn)
151-
}, { concurrency: 1 }))
152-
.catch((err) => {
153-
if ([].some.call(err, e => e.code === 'ENOENT')) {
154-
throw Object.assign(
148+
// Can't use race here because a generic error can happen before a ENOENT error, and can happen before a valid result
149+
return Promise.all(sri[sri.pickAlgorithm()].map((meta) => {
150+
return withContentSri(cache, meta, fn).catch((err) => {
151+
if (err.code === 'ENOENT') {
152+
return Object.assign(
155153
new Error('No matching content found for ' + sri.toString()),
156154
{ code: 'ENOENT' }
157155
)
158-
} else {
159-
throw err[0]
160156
}
157+
return err
161158
})
159+
})).then((results) => {
160+
// Return the first non error if it is found
161+
const result = results.find((r) => !(r instanceof Error))
162+
if (result) {
163+
return result
164+
}
165+
166+
// Throw the No matching content found error
167+
const enoentError = results.find((r) => r.code === 'ENOENT')
168+
if (enoentError) {
169+
throw enoentError
170+
}
171+
172+
// Throw generic error
173+
const genericError = results.find((r) => r instanceof Error)
174+
if (genericError) {
175+
throw genericError
176+
}
177+
})
162178
}
163179
}
164180

package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
],
5959
"license": "ISC",
6060
"dependencies": {
61-
"bluebird": "^3.5.5",
6261
"chownr": "^1.1.1",
6362
"figgy-pudding": "^3.5.1",
6463
"glob": "^7.1.4",

0 commit comments

Comments
 (0)