Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
✨ callback is always a function
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphtheninja committed Aug 29, 2017
1 parent 8a58d6a commit 1fac4fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Batch.prototype.write = function (callback) {
this.batch.write(function (err) {
if (err) { return dispatchError(levelup, new WriteError(err), callback) }
levelup.emit('batch', ops)
if (callback) { callback() }
callback()
})
} catch (err) {
throw new WriteError(err)
Expand Down
20 changes: 10 additions & 10 deletions lib/levelup.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ LevelUP.prototype.open = function (callback) {
if (!callback) [ callback, promise ] = promisify()

if (this.isOpen()) {
if (callback) { process.nextTick(function () { callback(null, self) }) }
process.nextTick(callback, null, self)
return promise
}

if (this._isOpening()) {
if (callback) this.once('open', function () { callback(null, self) })
this.once('open', function () { callback(null, self) })
return promise
}

Expand All @@ -89,7 +89,7 @@ LevelUP.prototype.open = function (callback) {
return dispatchError(self, new OpenError(err), callback)
}
self.db = self._db
if (callback) { callback(null, self) }
callback(null, self)
self.emit('open')
self.emit('ready')
})
Expand All @@ -106,13 +106,13 @@ LevelUP.prototype.close = function (callback) {
if (this.isOpen()) {
this.db.close(function () {
self.emit('closed')
if (callback) { callback.apply(null, arguments) }
callback.apply(null, arguments)
})
this.emit('closing')
this.db = new DeferredLevelDOWN(this._db)
} else if (this.isClosed() && callback) {
} else if (this.isClosed()) {
process.nextTick(callback)
} else if (this.db.status === 'closing' && callback) {
} else if (this.db.status === 'closing') {
this.once('closed', callback)
} else if (this._isOpening()) {
this.once('open', function () {
Expand Down Expand Up @@ -160,7 +160,7 @@ LevelUP.prototype.get = function (key, options, callback) {
}
return dispatchError(self, err, callback)
}
if (callback) { callback(null, value) }
callback(null, value)
})

return promise
Expand All @@ -187,7 +187,7 @@ LevelUP.prototype.put = function (key, value, options, callback) {
return dispatchError(self, new WriteError(err), callback)
}
self.emit('put', key, value)
if (callback) { callback() }
callback()
})

return promise
Expand All @@ -214,7 +214,7 @@ LevelUP.prototype.del = function (key, options, callback) {
return dispatchError(self, new WriteError(err), callback)
}
self.emit('del', key)
if (callback) { callback() }
callback()
})

return promise
Expand Down Expand Up @@ -250,7 +250,7 @@ LevelUP.prototype.batch = function (arr, options, callback) {
return dispatchError(self, new WriteError(err), callback)
}
self.emit('batch', arr)
if (callback) { callback() }
callback()
})

return promise
Expand Down

0 comments on commit 1fac4fb

Please sign in to comment.