Skip to content

Commit

Permalink
inLimbo -> isOpening
Browse files Browse the repository at this point in the history
inLimbo == !isOpen && !isClosed, which is the same as the
state 'new' or 'opening', but for the same reasons of
removing the CloseError, we never return the LevelUP object
in the state 'new', therefore inLimbo really means isOpening
  • Loading branch information
Lars-Magnus Skog committed Feb 16, 2013
1 parent a40c952 commit 6adb25a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/levelup.js
Expand Up @@ -54,7 +54,7 @@ var bridge = require('bindings')('levelup.node')

, isOpen = function () { return status == 'open' }
, isClosed = function () { return (/^clos/).test(status) }
, inLimbo = function () { return !isOpen() && !isClosed() }
, isOpening = function () { return status == 'opening' }
, dispatchError = function (error, callback) {
return callback ? callback(error) : levelup.emit('error', error)
}
Expand Down Expand Up @@ -94,7 +94,7 @@ var bridge = require('bindings')('levelup.node')
return this
}

if (status == 'opening')
if (isOpening())
return callback && this.once('open', callback.bind(null, null, this))

status = 'opening'
Expand Down Expand Up @@ -136,7 +136,7 @@ var bridge = require('bindings')('levelup.node')
callback()
} else if (status == 'closing' && callback) {
this.once('closed', callback)
} else if (status == 'opening') {
} else if (isOpening()) {
this.once('open', function () {
this.close(callback)
})
Expand All @@ -155,7 +155,7 @@ var bridge = require('bindings')('levelup.node')
, valueEnc
, err

if (inLimbo()) {
if (isOpening()) {
return this.once('ready', function () {
this.get(key_, options_, callback_)
})
Expand Down Expand Up @@ -192,7 +192,7 @@ var bridge = require('bindings')('levelup.node')
, key
, value

if (inLimbo()) {
if (isOpening()) {
return this.once('ready', function () {
this.put(key_, value_, options_, callback_)
})
Expand Down Expand Up @@ -227,7 +227,7 @@ var bridge = require('bindings')('levelup.node')
, err
, key

if (inLimbo()) {
if (isOpening()) {
return this.once('ready', function () {
this.del(key_, options_, callback_)
})
Expand Down Expand Up @@ -263,7 +263,7 @@ var bridge = require('bindings')('levelup.node')
, err
, arr

if (inLimbo()) {
if (isOpening()) {
return this.once('ready', function () {
this.batch(arr_, options_, callback_)
})
Expand Down Expand Up @@ -316,7 +316,7 @@ var bridge = require('bindings')('levelup.node')
LevelUP.prototype.approximateSize = function(start, end, callback) {
var err

if (inLimbo()) {
if (isOpening()) {
return this.once('ready', function () {
this.approximateSize(start, end, callback)
})
Expand Down

5 comments on commit 6adb25a

@rvagg
Copy link
Member

@rvagg rvagg commented on 6adb25a Feb 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of "limbo" was to handle the "closing" state too but I notice we're not really dealing with that now; you shouldn't be able to do anything while state == "opening" or "closing".

@ralphtheninja
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are dealing with it. If state == "opening" we just defer the operation and if it's "closing" it's not "open" so we always bail out.

@rvagg
Copy link
Member

@rvagg rvagg commented on 6adb25a Feb 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, fair enough, I'm having trouble fitting this all in my head at the moment after campjs (and I'm currently in a meeting supposed to be listening to something totally unrelated!)

@ralphtheninja
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out #76 and I think it's much clearer what is happening. The only thing that is important is that the state is "open" and we only do something if that's the case. The only other thing that happens is that we defer if it's "opening", all other states will callback/emit an error. #76 makes all methods handle different states the same way in a consistent matter.

@heapwolf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, enforcing this approach makes larger code bases far more maintainable.

Please sign in to comment.