Repository navigation
Promise API (userid/promises) for 2.1 - #11
Merged
Merged
Conversation
Every lookup was synchronous, so a slow user directory (LDAP, SSSD, NIS) blocked the event loop. The same six functions now also come as promises, like fs/promises and fs.promises, and run on the libuv thread pool. Native: the lookups are plain C++ returning Result<T> (value or Failure) and never touch JavaScript. Each is exported twice: sync, and *Async, which validates the argument on the main thread and runs the same lookup in a Napi::AsyncWorker that settles a promise. One function turns a Failure into an error for both, so results and errors are identical. The async-hooks resource is userid:<name>. NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS: terminating a worker thread with lookups in flight otherwise aborted the process, because the dying environment can't settle the promise and node-addon-api's rethrow escaped as a C++ exception. JS: loading and error decoration move to lib/native.cts, shared by lib/index.cts (sync) and lib/promises.cts. Every error, including a bad argument or Windows' ERR_USERID_UNSUPPORTED_PLATFORM, is a rejection, never a synchronous throw. Rejections get the caller's stack. Tests: every promise function against its sync twin on every kind of input; 1000 lookups in flight; worker threads, including terminating one mid-lookup; the thread-pool resource. test/event-loop.test.mts LD_PRELOADs a 300 ms getpwnam_r (CI, Linux) to prove the sync API blocks the loop and the promise API doesn't. The smoke test resolves userid/promises with each package manager and in the Bun runtime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cinderblock
marked this pull request as ready for review
November 12, 2026 04:20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a Promise-based API for the next minor release, 2.1.0. Every lookup today is synchronous, so a slow user directory (LDAP, SSSD, NIS) blocks the event loop. The promise versions run on the libuv thread pool.
Design
userid/promisesplusrequire('userid').promises, likefs/promisesandfs.promises. Same six functions andisSupported. No*Asyncfunctions.Result<T>(value orFailure) and never touch JavaScript. The sync binding throws on aFailure. The async binding validates the argument on the main thread, then runs the same lookup in aNapi::AsyncWorkerthat settles a promise. One function builds the error for both, so results and errors are identical.TypeError/RangeError), not found (ERR_USERID_NOT_FOUND), system errors (code/errno/syscall), and Windows'ERR_USERID_UNSUPPORTED_PLATFORM. Rejections carry the caller's stack.AbortSignalcould only abandon the promise while the pool thread stays busy. Not offered;Promise.racemakes that tradeoff explicit for callers who want it.NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS, and tested.Tests
userid:<name>proves the thread pool path.test/event-loop.test.mts: on Linux CI,LD_PRELOADs agetpwnam_rthat takes 300 ms. The sync API must block the event loop; the promise API must not; 4 parallel lookups must take about 300 ms in total.userid/promisesresolves with npm, pnpm and Bun, and works in the Bun runtime.Status
2.1.0, version bumpmaster(PR CI: download the Node.js headers once, with retries, before building #10)Not to be merged, tagged or published without explicit OK.
🤖 Generated with Claude Code