Stream: beginners

Topic: Stdin.line spins CPU


view this post on Zulip JRI98 (Dec 04 2023 at 14:44):

Hello. I don't know if I'm doing something wrong, but the following program makes my CPU spin at 100% before I give it any input. I'm on an M1 MacBook Pro

app "cli-tutorial"
    packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.0/bkGby8jb0tmZYsy2hg1E_B2QrCgcSTxdUlHtETwm5m4.tar.br" }
    imports [pf.Stdout, pf.Stdin, pf.Task]
    provides [main] to pf

main =
    Task.await Stdin.line \input ->
        when input is
            Input i -> Stdout.line i
            End -> Stdout.line "No input"

view this post on Zulip Richard Feldman (Dec 04 2023 at 14:45):

huh, that's surprising!

view this post on Zulip Richard Feldman (Dec 04 2023 at 14:46):

so the program otherwise behaves as expected? (Aside from the 100% CPU before you enter an inputs)

view this post on Zulip JRI98 (Dec 04 2023 at 14:47):

Wait, I spoke too soon. It is only when running it with the single command roc. No arguments.
And yes, apart from that the program behaves as expected

view this post on Zulip JRI98 (Dec 04 2023 at 14:48):

roc dev too

view this post on Zulip JRI98 (Dec 04 2023 at 14:50):

roc run main.roc or running the binary from roc build main.rocworks as expected. It's only the two invocations above

view this post on Zulip JRI98 (Dec 04 2023 at 15:16):

Summing up, it is a problem, but only when running roc or roc dev in a folder with a main.roc file with the contents above.
When running roc run main.roc or running the binary from roc build main.roc, the behaviour is as expected and the CPU does not spin.

view this post on Zulip Anton (Dec 04 2023 at 15:27):

I made #6181 for this.

view this post on Zulip Brendan Hansknecht (Dec 04 2023 at 17:54):

I probably broke this

view this post on Zulip Brendan Hansknecht (Dec 04 2023 at 17:54):

Not exactly sure how, but I think roc is waiting on the application to let it know that it has finished

view this post on Zulip Brendan Hansknecht (Dec 04 2023 at 17:54):

This is related to roc waiting for dbg and expect messages

view this post on Zulip Brendan Hansknecht (Dec 04 2023 at 17:55):

Maybe when I removed the dbg messages, I accidentally removed sending the termination message


Last updated: Jul 06 2025 at 12:14 UTC