Added finished callback to iterator.forRange() #33

Closed
wants to merge 2 commits into
from

2 participants

@ulikoehler

This pull request adds an additional, optional argument to iterator.forRange() which is a callback without argument.

This callback is called when the iterator has reached limitKey.

In any case, the finished callback is not called if any error occurs and the "normal" callback is guaranteed not to be called after the finished callback.

As the finished callback is optional, any call to forRange() not using the finished callback works exactly as before.

Currently there are no unit tests for this, but I tested the new feature in an expressjs app.

I think this feature is extremely important to node-leveldb - in my use case it is absolutely essential.

Also see Issue #28 for another request for this feature which should be fixed after merging this pull request.

@mikepb mikepb commented on the diff Jul 10, 2012
src/coffee/leveldb/iterator.coffee
###
forRange: ->
args = Array.prototype.slice.call arguments
+
+ #Optional finished callback
+ if typeof(args[args.length - 1]) is 'function' and typeof(args[args.length - 2]) is 'function'
+ finishedCallback = args.pop()
+ else
+ finishedCallback = ->{}
@mikepb
Collaborator
mikepb added a line comment Jul 10, 2012

Don't need to set finishedCallback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mikepb mikepb commented on the diff Jul 10, 2012
src/coffee/leveldb/iterator.coffee
@@ -132,6 +139,8 @@ exports.Iterator = class Iterator
callback null, @_getKey(options), @_getVal(options)
if not limit or limit isnt @_key.toString 'binary'
@next next
+ else
@mikepb
Collaborator
mikepb added a line comment Jul 10, 2012

else if finishedCallback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@my8bird my8bird added a commit that referenced this pull request Jul 13, 2012
@my8bird Merge pull #33 with refinements c66bf7a
@my8bird my8bird closed this Jul 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment