Limitations with Producer + Task
Closed this issue · 2 comments
Maybe there is something that I am missing, so please forgive me if this makes no sense or this library does it already, but I struggle with a problem.
Producers have the signature:
:: WidgetModel
-> (WidgetEvent -> IO ())
-> IO ()
while Tasks have this signature:
:: WigetModel
-> IO WidgetEvent
I often have the case, that I just need to do a -> IO ()
or Maybe a -> IO ()
. But either way, I need to either append a sendMsg
function as extra argument, that I have no use for, or I need to return some kind of NoOp
event, which is just useless WidgetEvent for that purpose.
I wonder if it's possible to just execute a task
(as the term producer and task are already used, let's call it Void
for that purpose) and return nothing back. Especially for dispose function f.e. this makes total sense to me.
Hi!
There is not a constructor for that specific use case. The idea of Task
is to run something in IO and provide a value back to the UI, so it makes sense that it requires a return value. Producers
allow doing something similar, although they can return zero or infinite values; they are a generalization of Task
.
I think the easiest way to handle this is using a helper function like:
voidTask :: IO () -> EventResponse s e sp ep
voidTask action = Producer (const action)
And then use it instead of Task:
handleEvent wenv node model evt = case evt of
Test -> [ voidTask $ putStrLn "Test" ]
...
Thank you.