question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Console<RT>.readLine repeatedly returning same input without blocking

See original GitHub issue

I modified the original example from https://github.com/louthy/language-ext/wiki/How-to-deal-with-side-effects#ioa which showcases the use of let:

var computation = from text  in readAllText(inpath)
                  let ntext = Capitalise(text)
                  from _     in writeAllText(outpath, ntext)
                  select unit;

to

var computation = repeat(from l in Console<RT>.readLine
                  let r = l + l
                  from _ in Console<RT>.writeLine(r)
                  select unit);

Expected

The computation should work as REPL which echos the input twice.

What happens

When I enter some chars and press Enter, the console is scrolling forever and repeats printing the output without waiting for new user input.

However, the following works:

var computation = repeat(from l in Console<RT>.readLine
                  from r in SuccessEff(l + l)
                  from _ in Console<RT>.writeLine(r)
                  select unit);

Am I doing something wrong or is this a bug?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
louthycommented, Apr 24, 2022

FYI: I haven’t forgotten this, I’m just working on a more robust solution for the Aff and Eff monads to turn them into DSLs rather than use the Thunks, which are adding a bit too much complexity (and causing edge case issues like this, which in itself was caused by a fix to another issue).

1reaction
timmi-on-railscommented, May 18, 2022

Thank you very much, I can confirm that both of my examples work as expected with version 4.1.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

capture keystroke without blocking [duplicate]
I usually use Console.ReadLine(); to capture a single keystroke. But this function blocks execution and keeps waiting for it to happen.
Read more >
Simultaneously write to and read from the console (i.e. use ...
This means that you can basically use the WriteLine and ReadLine methods simultaneously without ReadLine blocking the console preventing you ...
Read more >
C# Console.ReadLine Example
This reads input from the console. When the user presses enter, it returns a string. We can process this string like any other...
Read more >
Console.ReadLine Method (System)
NewLine property. The returned string does not contain the terminating character(s). By default, the method reads input from a 256-character input buffer.
Read more >
Repetition - C# Programming
ReadLine ()); // Read the input // if-else-if-else is one code block with multiple functions. // Check if number is too small. if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found