rvagg/nan — pull request #41 by rvagg (2013-11-15 10:10:58+00:00)
Title: 0.5.2-wip: make NanAsyncWorker.*Persistent() public

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:

```js
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.