Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mijicd
Copy link
Member

@mijicd mijicd commented Oct 19, 2020

Background

@LouisLotter identified an issue with default console implementation using the following program:

import zio._
import zio.console._

object TestCase extends App {
  def run(args: List[String]): URIO[ZEnv, ExitCode] =
    getStrLn.flatMap(line => putStrLnErr(line)).forever.ignore.map(_ => ExitCode.success)
}

Once this program was "bombed" with tens of thousands of writes to STDIN, it started loosing data. Rewriting the reading part as follows fixed the issue:

import zio._
import zio.console._

object TestCase extends App {
  val readLine = ZIO.effect(scala.io.StdIn.readLine)

  def run(args: List[String]): URIO[ZEnv, ExitCode] =
    readLine.flatMap(line =>  putStrLnErr(line)).forever.ignore.map(_ => ExitCode.success)
}

This revealed the problem with getStrLn implementation - unnecessary buffering.

Summary

  • Removed unnecessary buffering.
  • Fixed putStrError implementation (it was the same as putStrLnError).

@mijicd mijicd requested a review from jdegoes October 19, 2020 22:58
@mijicd mijicd merged commit 34be663 into zio:master Oct 19, 2020
@mijicd mijicd deleted the hotfix/console-buffering branch October 19, 2020 23:37
@LouisLotter
Copy link

Thanks, @mijicd , This resolved my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants