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

Commit 89e957f

Browse files
committed
refactor: call callbacks inside setImmediate
License: MIT Signed-off-by: Marcin Rataj <[email protected]>
1 parent d9ebf92 commit 89e957f

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/core/runtime/dns-browser.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ const _httpQueue = new PQueue({ concurrency: 4 })
1818
function unpackResponse (domain, response, callback) {
1919
if (response.Path) {
2020
return callback(null, response.Path)
21-
} else {
22-
const err = new Error(response.Message)
23-
return callback(err)
2421
}
22+
return callback(new Error(response.Message))
2523
}
2624

2725
module.exports = (domain, opts, callback) => {
@@ -49,15 +47,11 @@ module.exports = (domain, opts, callback) => {
4947
})
5048

5149
_httpQueue.add(() => fetch(url, { mode: 'cors' })
52-
.then((response) => {
53-
return response.json()
54-
})
50+
.then((response) => response.json())
5551
.then((response) => {
5652
cache.set(query, response, ttl)
57-
return unpackResponse(domain, response, callback)
58-
})
59-
.catch((error) => {
60-
callback(error)
53+
setImmediate(() => unpackResponse(domain, response, callback))
6154
})
55+
.catch((err) => setImmediate(() => callback(err)))
6256
)
6357
}

src/core/runtime/preload-browser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ module.exports = function preload (url, callback) {
2323
log.error('failed to preload', url, res.status, res.statusText)
2424
throw new Error(`failed to preload ${url}`)
2525
}
26-
return res.text()
26+
setImmediate(callback)
2727
})
28-
).then(() => callback(), callback)
28+
).catch((err) => setImmediate(() => callback(err)))
2929

3030
return {
3131
cancel: () => controller.abort()

0 commit comments

Comments
 (0)