From 2d8c89214ff70663d1130b1e45964bee6e6e6def Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 5 Mar 2020 14:57:17 +0000 Subject: [PATCH] chore: use blockstore.put instead of putMany --- src/index.js | 16 +++++++--------- test/bitswap.js | 10 ++++------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/index.js b/src/index.js index e9d23bb3..c81964c7 100644 --- a/src/index.js +++ b/src/index.js @@ -283,17 +283,15 @@ class Bitswap { async putMany (blocks) { // eslint-disable-line require-await const self = this - return this.blockstore.putMany(async function * () { - for await (const block of blocks) { - if (await self.blockstore.has(block.cid)) { - continue - } + for await (const block of blocks) { + if (await self.blockstore.has(block.cid)) { + continue + } - yield block + await this.blockstore.put(block) - self._sendHaveBlockNotifications(block) - } - }()) + self._sendHaveBlockNotifications(block) + } } /** diff --git a/test/bitswap.js b/test/bitswap.js index 206c5a49..3b8ea128 100644 --- a/test/bitswap.js +++ b/test/bitswap.js @@ -89,17 +89,15 @@ describe('bitswap without DHT', function () { // slow blockstore nodes[0].bitswap.blockstore = { has: sinon.stub().withArgs(block.cid).returns(false), - putMany: async function * (source) { // eslint-disable-line require-await - yield * source - } + put: sinon.stub() } // add the block to our want list const wantBlockPromise1 = nodes[0].bitswap.get(block.cid) - // oh look, a peer has sent it to us - this will trigger a `blockstore.putMany` which - // for our purposes is a batch operation so `self.blockstore.has(cid)` will still return - // false even though we've just yielded a block with that cid + // oh look, a peer has sent it to us - this will trigger a `blockstore.put` which + // is an async operation so `self.blockstore.has(cid)` will still return false + // until the write has completed await nodes[0].bitswap._receiveMessage(peerId, message) // block store did not have it