Skip to content
This repository was archived by the owner on Jan 7, 2022. It is now read-only.

Commit 67b3000

Browse files
martinheideggerJoe Hand
authored andcommitted
Making sure that a DAT is closed in the correct order (as errors might occur in the wrong order). (#226)
1 parent 5b59351 commit 67b3000

4 files changed

Lines changed: 91 additions & 63 deletions

File tree

dat.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var assert = require('assert')
22
var path = require('path')
3-
var multicb = require('multicb')
43
var xtend = require('xtend')
54
var untildify = require('untildify')
65
var importFiles = require('./lib/import-files')
@@ -210,17 +209,13 @@ Dat.prototype.close = function (cb) {
210209
var self = this
211210
self._closed = true
212211

213-
var done = multicb()
214-
closeNet(done())
215-
closeFileWatch(done())
216-
closeArchive(done())
217-
218-
done(cb)
219-
220-
function closeArchive (cb) {
221-
// self.archive.unreplicate()
222-
self.archive.close(cb)
223-
}
212+
closeNet(function (err) {
213+
if (err) debug('Error while closing network:', err.message)
214+
closeFileWatch(function () {
215+
// self.archive.unreplicate()
216+
self.archive.close(cb)
217+
})
218+
})
224219

225220
function closeNet (cb) {
226221
if (!self.network) return cb()
@@ -229,7 +224,11 @@ Dat.prototype.close = function (cb) {
229224

230225
function closeFileWatch (cb) {
231226
if (!self.importer) return cb()
227+
// Emitting an event, as imported doesn't emit an event on
228+
// destroy and there is no other means to see if this was called.
229+
self.importer.emit('destroy')
232230
self.importer.destroy()
231+
delete self.importer
233232
process.nextTick(cb)
234233
}
235234
}

0 commit comments

Comments
 (0)