Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

update dependencies and patch for racing condition #12

Merged
merged 1 commit into from
Apr 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test/repo-just-for-test*

test/test-repo-for-*
# Logs
logs
*.log
Expand Down Expand Up @@ -35,4 +35,4 @@ node_modules
.node_repl_history

lib
dist
dist
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"fs-blob-store": "^5.2.1",
"idb-plus-blob-store": "^1.0.0",
"ipfs-repo": "^0.6.1",
"idb-plus-blob-store": "^1.1.1",
"ipfs-repo": "^0.6.6",
"lodash": "^4.8.2",
"ncp": "^2.0.0",
"pre-commit": "^1.1.2",
Expand All @@ -60,4 +60,4 @@
"Stephen Whitmore <[email protected]>",
"dignifiedquire <[email protected]>"
]
}
}
22 changes: 21 additions & 1 deletion src/block-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,32 @@ function BlockService (ipfsRepo, exchange) {
let done = false

ws.write(block.data)

ws.once('error', (err) => {
done = true
callback(err)
})

ws.once('finish', () => {
if (!done) callback()
if (!done) {
// Important to note: Writing to a stream
// isn't an atomic process, because streams can be
// piped, and the finish of one only represents that
// the data was buffered to the next one.
// This is something known and 'accepted' on the
// streams API, however, since we expose a callback
// interface on BlockService and a streams one,
// the users will expect for the callback to be fired
// when the final write was concluded. We add a
// timeout to ensure that.
// TODO: Create an elegant way to understand when
// the block was actually flushed to disk. This
// means changing how the blob-stores and repo are
// implemented.
// One option, is polling till we check it
// is written.
setTimeout(callback, 150)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
})
ws.end()
}
Expand Down
2 changes: 1 addition & 1 deletion test/block-service-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = (repo) => {
})

it('store and get a block, with custom extension', (done) => {
const b = new Block('A random data block', 'ext')
const b = new Block('A random data block 2', 'ext')
bs.addBlock(b, (err) => {
expect(err).to.not.exist
bs.getBlock(b.key, 'ext', (err, block) => {
Expand Down