RadicalZephyr / sodium-rust

FRP implementation in Rust
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Add a testing help API for accumulating listeners #12

Open RadicalZephyr opened 8 months ago

RadicalZephyr commented 8 months ago

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 end Stream, 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 an AsyncIterator interface.

RadicalZephyr commented 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.