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

fix(block-service): return errors for addBlock #11

Merged
merged 1 commit into from
Apr 23, 2016
Merged
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
11 changes: 10 additions & 1 deletion src/block-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ const async = require('async')
function BlockService (ipfsRepo, exchange) {
this.addBlock = (block, callback) => {
const ws = ipfsRepo.datastore.createWriteStream(block.key, block.extension)

let done = false

ws.write(block.data)
ws.once('finish', callback)
ws.once('error', (err) => {
done = true
callback(err)
})
ws.once('finish', () => {
if (!done) callback()
})
ws.end()
}

Expand Down