What invariants should I support when using Control.Wire.Unsafe.Event?

I use Netwire to write a program that is driven by events from the network. I think there are three questions here:

  • What makes it Control.Wire.Unsafe.Eventunsafe? As the title says, what invariants do I need to support for safe use?

  • I decided that I need something like this: mapMaybeE :: Monad m => (a -> Maybe b) -> Wire s e m (Event a) (Event b). Context: I have messages coming from the network and I want to answer only some of them. Here is what I wrote:

    mapMaybeE :: Monad m => (a -> Maybe b) -> Wire s e m (Event a) (Event b)
    mapMaybeE f = arr go . arr (fmap f)
      where go WU.NoEvent = WU.NoEvent
            go (WU.Event Nothing) = WU.NoEvent
            go (WU.Event (Just a)) = WU.Event a
    

    Is it "legal"? Or should I block if there is no event?

  • Does Netwire make sense for this kind of problem? All the examples I've seen are games that work continuously. Here I only want to lay wires when I need to do something. Basically, these will be network events, but I can also do something on a timer. For instance. the event arrives, and after five seconds the program does something. It should not be looped until the time in the session is five seconds longer than when the event occurred.

+4
source share

Source: https://habr.com/ru/post/1695891/


All Articles