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

Commit 2480e12

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

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
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) {
89
[cid, path, options] = parseArgs(cid, path, options)
910

1011
if (options.preload !== false) {
1112
preload(cid)
1213
}
1314

14-
yield * ipld.resolve(cid, path, { signal: options.signal })
15+
let lastCid = cid
16+
let lastRemainderPath = path
17+
18+
if (path) {
19+
for await (const { value, remainderPath } of ipld.resolve(cid, path, {
20+
signal: options.signal
21+
})) {
22+
if (!CID.isCID(value)) {
23+
break
24+
}
25+
26+
lastRemainderPath = remainderPath
27+
lastCid = value
28+
}
29+
}
30+
31+
return {
32+
value: lastCid,
33+
remainderPath: lastRemainderPath || ''
34+
}
1535
})
1636
}

0 commit comments

Comments
 (0)