I've been using VSM more and more inside of Swift Concurrency code and notice that I keep repeating the same mistake over and over. When ever I write a function on a state model that returns a StateSequence, I mark that function as async even though inside said function I don't call any async functions. I believe it's because current the only way to have StateContainer to observe a StateSequence you need to call the observeAsync method which takes an async closure that returns a StateSequence.
But this is entirely unnecessary because creating a new instance of StateSequence is not an async options. StateSequence models an array of async closures that return a State. iterating through the sequence is an async operation.
So in this PR I added a new overload to the observe method that I think is a better fit when you need to only observer a StateSequence, but creating that sequence is not asynchronous. Taking the same code as above I would now write the function that returns the StateSequence like this:
Description
I've been using VSM more and more inside of Swift Concurrency code and notice that I keep repeating the same mistake over and over. When ever I write a function on a state model that returns a StateSequence, I mark that function as async even though inside said function I don't call any async functions. I believe it's because current the only way to have StateContainer to observe a StateSequence you need to call the
observeAsync
method which takes an async closure that returns aStateSequence
.Take this method as an example;
I wrote it this way because when I call it I typically write it like this:
But this is entirely unnecessary because creating a new instance of StateSequence is not an async options. StateSequence models an array of async closures that return a
State
. iterating through the sequence is an async operation.So in this PR I added a new overload to the
observe
method that I think is a better fit when you need to only observer a StateSequence, but creating that sequence is not asynchronous. Taking the same code as above I would now write the function that returns the StateSequence like this:And when I go to observe those state changes I would call the new observe method that would look like this:
I think this should prevent other users from making the same mistake I keep making.
Type of Change
Checklist