From acea55fecb0ec4d4906ce06a898b5fa2d15c45f4 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 2 Jul 2019 15:33:04 +0100 Subject: [PATCH] fix: wait for one key to be the required key not all (#490) * fix: wait for one key to be the required key not all Also, every returns true if there's no items in the list so this was returning a false positive. * fix: iteratee not updating list --- src/bitswap/utils.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bitswap/utils.js b/src/bitswap/utils.js index 5a2c9c35..c5f2de34 100644 --- a/src/bitswap/utils.js +++ b/src/bitswap/utils.js @@ -16,8 +16,14 @@ function waitForWantlistKey (ipfs, key, opts, cb) { setTimeout(() => { timedOut = true }, opts.timeout) - const test = () => timedOut ? true : list.Keys.every(k => k['/'] === key) - const iteratee = (cb) => ipfs.bitswap.wantlist(opts.peerId, cb) + const test = () => timedOut ? true : list.Keys.some(k => k['/'] === key) + const iteratee = (cb) => { + ipfs.bitswap.wantlist(opts.peerId, (err, nextList) => { + if (err) return cb(err) + list = nextList + cb() + }) + } until(test, iteratee, (err) => { if (err) return cb(err)