Skip to content

Commit

Permalink
Cleanly handle closing of active scan feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rik Smith-Unna committed Jun 25, 2017
1 parent c853c99 commit 9f38e3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 1 addition & 2 deletions app/client/lib/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ function Datasource (key, opts) {
self.connectmeta = cb => {
self.metadata = hyperdrive(storage(self.jsondir), self.key, {
latest: true,
sparse: false,
live: false
sparse: true,
})

self.metadata.once('ready', () => {
Expand Down
12 changes: 10 additions & 2 deletions app/client/models/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ module.exports = (state, bus) => {
const tags = {}
let count = 0

if (activescan) activescan.destroy()
if (activescan) {
activescan.destroy()
activescan = null
}

let scanstream = activescan = state.collection.docstore.createReadStream().on(
'data', data => {
Expand All @@ -50,7 +53,12 @@ module.exports = (state, bus) => {

eos(scanstream, err => {
if (err) {
throw err
if (err.message == 'premature close') {
// activescan was destroyed
return
} else {
throw err
}
} else {
state.collectioncount = count
bus.emit('tags:replace', tags)
Expand Down

0 comments on commit 9f38e3f

Please sign in to comment.