hs-async
hs-async copied to clipboard
Subtlety in Array Demo Implementation
In the first array demo example (interacting with a text-based select control), there's an ordering requirement which doesn't seem to be clearly expressed. Key presses are being sent to 2 channels and the correctness of the program depends on the selector code processing the keys and updating the array before the printing code runs.
Below are two lines from the demo:
[k0 k1] (multiplex keys 2)
k1 (filter #{:up :down} k1)
I've made a couple of changes to these lines. After my changes, I would expect the demo to continue working properly with the up and down arrows. But this turns out not to be the case.
For example, suppose we needed to apply the filter to k0 instead of k1:
[k0 k1] (multiplex keys 2)
k0 (filter #{:up :down} k0)
Another example: suppose we didn't need to filter either channel and had decided to reverse the order of k0 and k1:
[k1 k0] (multiplex keys 2)
Both of these variations cause the printed list to lag behind the in-memory state of the list. Given the code changes, I think this behavioral change is non-obvious.
Should the code be changed to more clearly express the ordering requirement or am I missing some detail of the original demo implementation?