Hi all. I asked chatgpt: accept input for only n seconds in erlang and it gave me back:
-module(input_timeout).
-export([start/0, input/1]).
start() ->
Self = self(),
Timeout = 5, % 5 seconds timeout
spawn(fun() -> timer:sleep(Timeout * 1000), Self ! timeout end),
input(Timeout).
input(Timeout) ->
io:format("Enter something within ~w seconds: ", [Timeout]),
receive
{From, Msg} ->
From ! {input, Msg}
after Timeout * 1000 ->
io:format("~nTime's up!~n"),
exit(timeout)
end.
But typing in text does nothing and only shows up after the timeout happens. How do you type input in the erlang shell with this type of code?