You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say I have a source channel which contains the result of an expensive operation. I have a reader that reads from this source channel every 1 second. I want to read from the source, but only read the latest (or cached) value.
test('The LatestBuffer can be used to store the last value that went through the channel',()=>goPromise(function*(){// Arrangeconstc=chan(newLatestBuffer())// Actconstv1=yieldtake(c)yieldput(c,12)constv2=yieldtake(c)constv3=yieldtake(c)yieldput(c,24)constv4=yieldtake(c)// Assertexpect(v1).toBeUndefined()expect(v2).toBe(12)expect(v3).toBe(12)expect(v4).toBe(24)}))
Let's say I have a source channel which contains the result of an expensive operation. I have a reader that reads from this source channel every 1 second. I want to read from the source, but only read the latest (or cached) value.
I think there a couple ways to do this:
With a custom buffer
With a couple goroutines
Is one better than the other? I think I like LatestBuffer more. Is there a better way? Would this be nice to have in js-csp?
Thanks!
The text was updated successfully, but these errors were encountered: