Stream: beginners

Topic: Task Timeout


view this post on Zulip Daniel Herrmann (Feb 20 2024 at 14:30):

Hi,
I am trying to implement a simple terminal game using the basic-cli platform. I am trying to read user input in a non blocking way. To simulate this I wanted to assing some time in the loop to read user input and ignore it if no input is received withing the given time. Does anyone know how to implement a function that receices a task and a time and returns the task result if the task completes or a Timeout error if the time runs out?

view this post on Zulip Brendan Hansknecht (Feb 20 2024 at 14:56):

I don't think that is currently supported in basic cli. Someone would need to add the feature to the platform. Though it might be hard to add into the platform in a generic way with the current platform interface (without effect interpreters).

So probably would currently need to be added for specific operation.

view this post on Zulip Anton (Feb 20 2024 at 15:08):

I think you can probably achieve what you want with Tty.enableRawMode, see this example.

view this post on Zulip Daniel Herrmann (Feb 20 2024 at 15:24):

I am using Tty.enableRawMode, the example is almost what I wanted, except the input is blocking, because the GUI doenst neet to update if there is no user input. Maybe I do need to implement something to be able to add a timeout to a task

view this post on Zulip Anton (Feb 20 2024 at 15:33):

Right, I understand now

view this post on Zulip Daniel Herrmann (Feb 20 2024 at 16:53):

Or implement a turn based game with no idle animations :P

view this post on Zulip Anton (Feb 20 2024 at 16:59):

That seems easier :sweat_smile:

view this post on Zulip Luke Boswell (Feb 20 2024 at 19:54):

Yeah, this is something I've explored a bit while making terminal UI games. I came to the conclusion it's not possible without Task.map2 and the effect interpreters.

view this post on Zulip Jeffrey Mudge (Mar 25 2024 at 13:31):

Luke Boswell said:

Yeah, this is something I've explored a bit while making terminal UI games. I came to the conclusion it's not possible without Task.map2 and the effect interpreters.

Is there a place to track the implementation of Task.map2? I've been working on using your roc-ansi package to create an MPD (Music Player Daemon) TUI client and I've gotten to the point where I can get and display the current playlist from the server, but it doesn't auto update since the next loop is stuck waiting for input.

I wanted to set a timeout on getting that input and jump to the next iteration of the loop, but it sounds like that's not possible with the basic-cli platform at the moment.

view this post on Zulip Luke Boswell (Mar 25 2024 at 18:44):

I think we know what needs to be done, but it just needs someone to implement it in the compiler. I think the next step from memory is to implement a paricular function which can take any roc type and give it a good name. Then this will enable the changes we need for glue. @Richard Feldman or @Folkert de Vries could give a better explanation. Is this something you would be interested in working on?

I don't think we've made an issie to track it or anything, so any updates or discussion would most likely be in zulip chat.

view this post on Zulip Luke Boswell (Mar 25 2024 at 18:49):

Oh actually I think @doubledup might be working on things?

view this post on Zulip Jeffrey Mudge (Mar 25 2024 at 18:54):

OK, thanks. I did search in Zulip and Github issues, but thought maybe I'd missed something.

I think compiler work is beyond my abilities at this point, so I think I'll wait until someone one else is able to do it. There are plenty of other things I can play around with in the meantime.


Last updated: Jul 05 2025 at 12:14 UTC