workers-rs
workers-rs copied to clipboard
async initializer for durable objects
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.
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.
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