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

Commit 6ba72d9

Browse files
committed
fix(core): return promise from 'dag.resolve'
1 parent 343bd45 commit 6ba72d9

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
'use strict'
22

3+
const CID = require('cids')
34
const { parseArgs } = require('./utils')
45
const { withTimeoutOption } = require('../../utils')
56

67
module.exports = ({ ipld, preload }) => {
7-
return withTimeoutOption(async function * resolve (cid, path, options) { // eslint-disable-line require-await
8+
return withTimeoutOption(async function resolve (cid, path, options) { // eslint-disable-line require-await
89
[cid, path, options] = parseArgs(cid, path, options)
910

1011
if (options.preload !== false) {
1112
preload(cid)
1213
}
14+
const { signal, timeout } = options
1315

14-
yield * ipld.resolve(cid, path, { signal: options.signal })
16+
try {
17+
let lastCid = cid
18+
let lastRemainderPath = path
19+
20+
if (path) {
21+
for await (const { value, remainderPath } of ipld.resolve(cid, path, {
22+
signal,
23+
timeout
24+
})) {
25+
if (!CID.isCID(value)) {
26+
break
27+
}
28+
29+
lastRemainderPath = remainderPath
30+
lastCid = value
31+
}
32+
}
33+
34+
return {
35+
value: lastCid,
36+
remainderPath: lastRemainderPath || ''
37+
}
38+
39+
} finally {
40+
if (release) {
41+
release()
42+
}
43+
}
1544
})
1645
}

0 commit comments

Comments
 (0)