I am using a global signal in an event handler like the following:
let mut value = VALUE.write();
match &mut value {
Variant1 => {
spawn(async move {
let new_value = do_something().await;
*VALUE.write() = Variant3;
});
}
Variant2(inner) => *inner += 123
... // lots of other variants
}
Is this okay?
My concerns come from the following:
- Do read and write borrows on global signals wait until they can get a borrow, and only error when I try to get an incompatible borrow on the same thread?
- Do I need to worry about deadlocks?
- Aren't global signals not safe across threads since they are
UnsyncStorage?
For context, I am wanting to modify VALUE in a nice, easy way.
Where I can say Variant2(inner) => *inner += 123 instead of Variant2(inner) => *VALUE.write() = Variant2(inner + 123)
and have to explicitly call VALUE.write() and fully set it or pattern match to modify parts of it.
I have also thought about making the entire thing async, but that seems to be even worse because then the write lock would persist until do_something is completed.
Thanks for the help!