Skip to content

0.5.2-wip: make NanAsyncWorker.*Persistent() public#41

Merged
rvagg merged 1 commit intomasterfrom
0.5.2-wip
Nov 16, 2013
Merged

0.5.2-wip: make NanAsyncWorker.*Persistent() public#41
rvagg merged 1 commit intomasterfrom
0.5.2-wip

Conversation

@rvagg
Copy link
Copy Markdown
Member

@rvagg rvagg commented Nov 15, 2013

A small change to NanAsyncWorker, I'd like to make SavePersistent() and GetFromPersistent() public so I can use them from the outside. I'm finding that best practice might be to save a persistent of the parent object on each async call so GC doesn't get a chance to clean up the parent if there is no reference left in JS-land. For instance:

function () {
  var batch = db.batch()
  batch.put('foo', 'bar')
  batch.write(function () {
    // no JS reference here, `batch` is free to be cleaned up prior to this
    // if the `write()` call takes a significantly long time
  })
}

so instead of resorting to referencing hacks in JS-land, if you put the reference to the parent object, in this case batch into the NanAsyncWorker, in this case for the write() work, then it is kept around until the worker is cleaned up.

This is much cleaner if you can do this from outside NanAsyncWorker.

Having said all that, I think my projects might be the only ones actually using NanAsyncWorker so this is mainly FYI but I'd appreciate any feedback, comments or objections before merging.

rvagg added a commit that referenced this pull request Nov 16, 2013
0.5.2-wip: make NanAsyncWorker.*Persistent() public
@rvagg rvagg merged commit 8e40404 into master Nov 16, 2013
@rvagg rvagg deleted the 0.5.2-wip branch November 16, 2013 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant