2021/7/16 Workers Runtime Release Notes

Changes this week:

  • Workers can now make up to 1000 subrequests to Durable Objects from a within a single request invocation, up from the prior limit of 50.
  • Major changes to Durable Objects implementation, the details of which will be the subject of an upcoming blog post. In theory, the changes should not harm existing apps, except to make them faster. Please let us know if you observe anything odd.
  • Durable Object constructors may now initiate I/O, such as fetch() calls.
  • Added Durable Objects state.blockConcurrencyWhile() API useful for delaying delivery of requests and other events while performing some critical state-affecting task. For example, this can be used to perform start-up initialization in an object’s constructor.
  • In Durable Objects, the callback passed to storage.transaction() can now return a value, which will be propagated as the return value of the transaction() call.

Hey can you tag this with the usual WorkersReleaseNotes tag, please? I almost missed it, and it’s a BIG update.

Please clarify the valid usage of state.blockConcurrencyWhile():

  1. Can we have any following statements in the constructor() after state.blockConcurrencyWhile()? For example if I had this code:
constructor(state, env) {
  let ret = this.state.blockConcurrencyWhile(async () => {
    await ...; // and so on
    return 2;
  this.myvar = ret;

Will this be executed as we expect? First the blockConcurrencyWhile() closure, then its return value will be assigned to this.myvar? The confusion comes from the fact that having an “async” callback in a non-async constructor() is impossible in standard node.js?

  1. Can we have multiple state.blockConcurrencyWhile() statements in the constructor, as well as in the fetch() handler?

Thank you.


blockConcurrencyWhile is an async function, so it returns a promise. In your example, ret will be a promise for the eventual result of blockConcurrencyWhile. The callback will not actually execute until the next tick of the event loop, i.e. after the constructor returns.

You can have multiple blockConcurrentlyWhile statements, sure. They will block each other, so only one callback will run at a time. You can put them anywhere, not just in constructors.

1 Like