# Readline with default value if no input after timeout

**URL:** <https://discourse.julialang.org/t/readline-with-default-value-if-no-input-after-timeout/100388>\
**Category:** General Usage\
**Created:** [June 15, 2023, 10:43am UTC](https://discourse.julialang.org/t/readline-with-default-value-if-no-input-after-timeout/100388 "2023-06-15T10:43:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)\
**Post date:** [June 15, 2023, 10:43am UTC](https://discourse.julialang.org/t/readline-with-default-value-if-no-input-after-timeout/100388/1 "2023-06-15T10:43:46Z")

</div>

I am to write a code that asks for a prompt from the REPL but defaults to some predefined string if the user does not input anything within e.g. 10 seconds.

I was thinking of using `readline` but I can’t seem to find a way to make it stop if no input is given after a certain period.

How would one achieve this?

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [June 15, 2023, 12:12pm UTC](https://discourse.julialang.org/t/readline-with-default-value-if-no-input-after-timeout/100388/2 "2023-06-15T12:12:21Z")

</div>

Probably not the most elegant solution, but it works:

```julia
msg = Channel{String}(1)

task = Task() do
    try
        eof(stdin)
        put!(msg, readline(stdin))
    catch
        put!(msg, "no input received!")
    end
end

interrupter = Task() do
    sleep(1)
    if !istaskdone(task)
        Base.throwto(task, InterruptException())
    end
end

schedule(interrupter)
schedule(task)
println("waiting ..")
wait(task)
println(take!(msg))

```
