Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block reading of uart and usb #2739

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft

Conversation

sago35
Copy link
Member

@sago35 sago35 commented Mar 28, 2022

caution

  • This change breaks compatibility with previous versions of TinyGo.
  • This change improves compatibility with Go.

#2625 allows the use of os.Stdin.
os.Stdin and machine.Serial are the same, but the behavior of the following code is different.
When used as os.Stdin, it blocks when there is no data.
However, if machine.Serial, machine.UART or machine.USB is used directly, it will not block.

// It works as expected.
scanner := bufio.NewScanner(os.Stdin)
// Not working as expected.
scanner := bufio.NewScanner(machine.Serial)

I believe that according to the Go documentation, if there is no data, it should block or return an error.

https://pkg.go.dev/io#Reader
Implementations of Read are discouraged from returning a zero byte count with a nil error, except when len(p) == 0.

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.

1 participant