Orchestrating the Subscription
Orchestrating the flow is kind of fun, and you’ll see a, ah, clever use of JavaScript mechanics. There are two main functions, and a couple of helpers. One of the main functions orchestrates calls to getNextBatchOfMessages and processBatch. We’ll call this function tick. The other main function orchestrates calls to tick, only doing so when it’s time to poll again. We’ll call this function poll. Let’s go through everything in the order it would all be called.
First, the polling cycle doesn’t begin right when a subscriber instantiates a subscription. This is by design—we don’t want our tests to actually start a polling cycle, for example. So there’s a start function the outside world will call to start the subscription, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access