reactive-banana time delays

前端 未结 2 919
误落风尘
误落风尘 2021-02-08 17:59

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 a

2条回答
  •  旧巷少年郎
    2021-02-08 18:29

    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.

提交回复
热议问题