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

Commit

Permalink
💥 remove dispatchError(), 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 1fac4fb commit bb3df7b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
3 changes: 1 addition & 2 deletions lib/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

var util = require('./util')
var WriteError = require('level-errors').WriteError
var dispatchError = util.dispatchError
var promisify = util.promisify

function Batch (levelup) {
Expand Down Expand Up @@ -64,7 +63,7 @@ Batch.prototype.write = function (callback) {

try {
this.batch.write(function (err) {
if (err) { return dispatchError(levelup, new WriteError(err), callback) }
if (err) { return callback(new WriteError(err)) }
levelup.emit('batch', ops)
callback()
})
Expand Down
14 changes: 6 additions & 8 deletions lib/levelup.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var NotFoundError = errors.NotFoundError
var OpenError = errors.OpenError
var InitializationError = errors.InitializationError

var dispatchError = util.dispatchError
var promisify = util.promisify

// Possible AbstractLevelDOWN#status values:
Expand Down Expand Up @@ -86,7 +85,7 @@ LevelUP.prototype.open = function (callback) {

this.db.open(this.options, function (err) {
if (err) {
return dispatchError(self, new OpenError(err), callback)
return callback(new OpenError(err))
}
self.db = self._db
callback(null, self)
Expand Down Expand Up @@ -140,7 +139,6 @@ LevelUP.prototype.get = function (key, options, callback) {
throw new ReadError('get() requires a key argument')
}

var self = this
var promise

callback = getCallback(options, callback)
Expand All @@ -158,7 +156,7 @@ LevelUP.prototype.get = function (key, options, callback) {
} else {
err = new ReadError(err)
}
return dispatchError(self, err, callback)
return callback(err)
}
callback(null, value)
})
Expand All @@ -184,7 +182,7 @@ LevelUP.prototype.put = function (key, value, options, callback) {

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

this.db.del(key, options, function (err) {
if (err) {
return dispatchError(self, new WriteError(err), callback)
return callback(new WriteError(err))
}
self.emit('del', key)
callback()
Expand Down Expand Up @@ -247,7 +245,7 @@ LevelUP.prototype.batch = function (arr, options, callback) {

this.db.batch(arr, options, function (err) {
if (err) {
return dispatchError(self, new WriteError(err), callback)
return callback(new WriteError(err))
}
self.emit('batch', arr)
callback()
Expand Down Expand Up @@ -287,7 +285,7 @@ function getOptions (options) {

function maybeError (db, callback) {
if (!db._isOpening() && !db.isOpen()) {
dispatchError(db, new ReadError('Database is not open'), callback)
callback(new ReadError('Database is not open'))
return true
}
}
Expand Down
5 changes: 0 additions & 5 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
* <https://github.com/level/levelup/blob/master/LICENSE.md>
*/

function dispatchError (db, error, callback) {
typeof callback === 'function' ? callback(error) : db.emit('error', error)
}

function promisify () {
var callback
var promise = new Promise(function (resolve, reject) {
Expand All @@ -20,6 +16,5 @@ function promisify () {
}

module.exports = {
dispatchError: dispatchError,
promisify: promisify
}

0 comments on commit bb3df7b

Please sign in to comment.