Skip to content

napi-asyncworker-example missing scope #142

Description

@rynz

void SimpleAsyncWorker::OnOK() {
std::string msg = "SimpleAsyncWorker returning after 'working' " + std::to_string(runTime) + " seconds.";
Callback().Call({Env().Null(), String::New(Env(), msg)});
};

This seems to be the only example that doesn't call:

Napi::HandleScope scope(Env());

Should this example include that too?

Activity

  1. gabrielschulhof commented on Jun 15, 2020

    @gabrielschulhof
    Contributor

    @rynz actually, it should be the other way around. Node.js ensures that all scopes are present by the time the OnOK/OnError callbacks get called. Thanks for noticing the discrepancy!

    We have additional documentation here: https://github.com/nodejs/node-addon-api/blob/master/doc/object_lifetime_management.md

  2. rynz commented on Jun 15, 2020

    @rynz
    Author

    @gabrielschulhof thank you!

  3. gotnone commented on Jul 4, 2020

    @gotnone

    Can someone who is more familiar with this than I am check to see if there is still bad example code in node-addon-api/doc/async_worker.md It appears that the OnOK example is using the Napi::HandleScope when it is not necessary.

    Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions