Skip to content

Conversation

@wemeetagain
Copy link
Member

  • do not merge, this is just for demo purposes
  • This shows how work can be delegated to a background worker and have a promise returned which is resolved when the work is complete
    • the include/ folder is just the napi headers
    • this just uses https://nodejs.org/api/n-api.html#simple-asynchronous-operations
    • look at the additions to zig/leveldb.zig, its quite verbose, but it goes like:
      • leveldb_db_get_promise gets the input, creates+returns the promise and creates+queues the async work
      • leveldb_db_get_execute_callback is where the "heavy work / io" is performed (can't use napi in this fn)
      • leveldb_db_get_complete_callback is where the result is wrapped / napi-ified
  • the added test shows that (at least for this microbenchmark) that the sync version is faster than even the time to return the promise in the async version
    • this shows that we need to carefully apply this pattern only where it "makes sense", eg where the work takes more than ~0.1ms

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.

2 participants