workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

async initializer for durable objects

Open cometkim opened this issue 2 years ago • 2 comments

I'm not sure it is already supported in workers-rs. But hopefully there would be an equivalent binding to blockConcurrencyWhile in JavaScript. Something like async fn new(...) -> Self

I use a pattern that refers to configs stored in KV when initializing DOs through it, but I don't know how to do the same in a workers-rs project.

cometkim avatar May 09 '22 05:05 cometkim

I'm currently writing a durable object in rust and managing loading state from persistent storage to in memory is just awkward. I end up needing an enum field in my struct for Loading / Ready, and then checking that all over. I'm thinking of working around this awkwardness by making the top fetch handler just load-if-not-done-yet and then delegate to the state inside that enum.

Also, in order to actually support loading, new needs to return a Result; it would have to be allowed to fail.

tv42 avatar Jun 28 '22 22:06 tv42

Same need here.

I think an async new() implementation could handle a failure to read from storage and in that case return a new instance created from default values - and avoid the need for new() to return Result

andrewdavidmackenzie avatar Dec 22 '23 13:12 andrewdavidmackenzie