Skip to content

Promisify WNS sends - #298

Merged
alex-friedl merged 2 commits into
masterfrom
refactor/wns-promises
Nov 29, 2026
Merged

alex-friedl merged 2 commits into
masterfrom
refactor/wns-promises

Conversation

@alex-friedl

@alex-friedl alex-friedl commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

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.promisify would 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

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>
@alex-friedl alex-friedl self-assigned this Nov 29, 2026
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>
@alex-friedl
alex-friedl merged commit 42d9e89 into master Nov 29, 2026
6 checks passed
@alex-friedl
alex-friedl deleted the refactor/wns-promises branch November 29, 2026 22:42
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.

1 participant