reactive-banana time delays

帅比萌擦擦* 提交于 2020-01-12 05:27:06

问题


I have scoured the documentation of reactive-banana, and I can't find a way to specify explicit time delays. Say, for example, I would like to take an Event t a and shift all of its occurrences 1 second into the future; or get an event that fires 1 second from now (within Moment t); or anything like that. Are explicit delays representable in reactive-banana? If not, how do users implement, e.g., echoing input delayed by a second?


回答1:


As Ben indicates, this is correct: reactive-banana is no built-in notion of time and delays.

The main reason is that it is hard to guarantee that logical time and real time agree. What happens when a mouse click happens in real time before the logical time of an event which could not yet be calculated, i.e. whose real time dallies behind its logical time?

However, it is still possible to deal with time by using external timer events. Have a look at the Wave.hs example.




回答2:


I'm not an expert by any means, but I've used an older reactive-banana for a program with exactly this need (I don't have the code on hand at the moment, unfortunately).

I think that explicit delays don't fit super-naturally within the reactive-banana framework because you're always implicitly dealing with some sort of abstract time. Delaying by particular intervals requires dealing with the real world notion of time. I can see that it would be very hard to say what something like union event (delay 1.0 event) would mean in terms of the authoritative model where type Event a = [Maybe a]: should it be [a, b, a, b] or [a, a, b, b]? As I've been thinking of it, the problem is that which of those two should result is unspecified without considering operational runtime details.

But you can do it "around" the reactive-banana framework by wiring up an IO action to the event you want to delay that sleeps for a while (not in the main thread, obviously) and then fires a different event. I believe I was able to wrap all that logic up in a function I could call from the NetworkDescription monad (this was before the Moment monad existed) to get my new delayed event.



来源:https://stackoverflow.com/questions/19668940/reactive-banana-time-delays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!