Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] sync subscription utility #602

Merged
merged 2 commits into from Oct 3, 2023
Merged

[FEAT] sync subscription utility #602

merged 2 commits into from Oct 3, 2023

Conversation

aricart
Copy link
Member

@aricart aricart commented Sep 29, 2023

[FEAT] added a utility function syncIterator() to wrap an AsyncIterables so that elements can be extracted in a sync faction. Note messages and elements will continue to buffer in the iterable, so if you don't drain it or stop its source memory will grow - this is syntactic sugar, as the iterator can be had via src[Symbol.asyncIterator](). This can be useful to process subscription messages one at a time; this is especially true on tests.

const sub = nc.subscribe("foo");
nc.publish("foo");
nc.publish("foo");
const sync = syncIterator(sub);
console.log((await sync.next()).subject);
console.log((await sync.next()).subject);

…les so that elements can be extracted in a `sync` faction - this is syntactic sugar, as the iterator can be had via `src[Symbol.asyncIterator]()`. This can be useful, to process subscription messages one at a time.
@aricart aricart marked this pull request as ready for review September 29, 2023 14:53
@aricart aricart requested a review from Jarema September 29, 2023 14:53
Copy link

@scottf scottf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aricart aricart temporarily deployed to CI September 29, 2023 16:43 — with GitHub Actions Inactive
Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@aricart aricart merged commit b0f16b0 into main Oct 3, 2023
3 checks passed
@aricart aricart deleted the sync-sub branch October 26, 2023 15:35
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.

None yet

3 participants