Repository navigation
Promisify WNS sends - #298
Merged
Merged
Conversation
Replace the callback recursion for access-token sends with an async loop over promisified wns calls. Results, per-destination errors and token refresh behave as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With asynchronous callbacks, the old recursion left the rejection of a synchronous throw unhandled until the next callback, which crashes Node. 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.
Sending to WNS with an access token used a callback recursion: each callback started the next request, and a side array of promises tracked synchronous throws. That needed two eslint-disable comments and carried a TODO to replace it.
What changed
Each wns call is now wrapped in a promise that resolves with whatever wns called back with, error or response. It only rejects when wns throws synchronously, so a throw still fails the whole send while a callback error stays a per-destination failure.
util.promisifywould reject in both cases, which is why the wrapper is hand-written.With an access token, an async loop sends one request at a time and passes the refreshed token on to the next. After a throw it keeps sending to the remaining destinations and then rejects with the first error, as before. Without a token, all requests still go out in parallel.
Results, per-destination errors and token refresh are unchanged. The existing WNS tests cover all of them and pass without modification.
Fixed along the way
When wns threw synchronously and called back asynchronously, as the real library does, the old code left the rejection without a handler until the next callback arrived. Node treats that as an unhandled rejection and exits by default. The rewrite handles it right away. A new test covers this case and fails on the old code.
A synchronous error inside the WNS sender also no longer skips the ADM and Web Push sends of the same
send()call.send()still rejects with that error.🤖 Generated with Claude Code