Behavior of blockConcurrencyWhile when used outside of durable object constructor

The examples for usage always show this being used in the constructor of a durable object to prevent concurrent execution of requests while initialization is not yet done. Is this the only way this should be used? In our project we're using blockConcurrencyWhile in one of many routes handled by the fetch method. What is the expected behaviour in this case? How should requests or alarms that have already kicked of before calling blockConcurrencyWhile for another request behave? Will they be stopped or could they be executing concurrently?
2 Replies
Vy
Vy14mo ago
Hi @Matthias. Some additional info: * blockConcurrentlyWhile can be used outside DO constructor * The blockConcurrentlyWhile takes effect right away, pausing everything else including in-flight requests/alarms Thank you for the feedback that this info is missing in our docs! We will work to remedy that. If you’re able to, can you share more about why blockConcurrentlyWhile is useful in your routes?
Matthias
MatthiasOP14mo ago
Hey, thanks for the response. We're spinning up external resources on demand when specific routes are called. We don't want duplicate resources created in case requests come in concurrently. So we'd like to pause any other requests while the resources are spun up.
Want results from more Discord servers?
Add your server