Open RadicalZephyr opened 8 months ago
Another possibility that is closer to the current API would be to just provide an accumulating listener that returns the collected values on demand or when you call unlisten
. Under the hood this could basically work the same way as the standard test pattern.
Testing a Sodium system require quite a bit of boilerplate currently, particularly because tests are not inherently reactive, and so making assertions is a bit convoluted.
The typical pattern used inside the library is to create an
Arc<Mutex<Vec<T>>
and share this between a listener to accumulate results from the endStream
, and the code outside the system that will manipulate the tests.It would be highly convenient if you could basically treat a Sodium system as an iterator essentially.
One possible solution would be to provide an async interface such that a Sodium
Stream
presents anAsyncIterator
interface.