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

Kadai3-1 uobikiemukot #47

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Kadai3-1 uobikiemukot #47

wants to merge 8 commits into from

Conversation

uobikiemukot
Copy link
Contributor

@uobikiemukot uobikiemukot commented Nov 26, 2018

課題3-1

  • タイピングゲームを作ろう
    • 標準出力に英単語を出す(出すものは自由)
    • 標準入力から1行受け取る
    • 制限時間内に何問解けたか表示する

時間が足りず、最低限のものしかできていません 😿

Copy link

@mizkei mizkei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメントしましたので、参考にしていただければと思います


// ReadInput read io.Reader and return string channel
func ReadInput(ctx context.Context, in io.Reader) <-chan string {
ch := make(chan string, 0)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size 0の場合は特に指定なしでも問題ありません

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed: 33fc2e4


func main() {
bg := context.Background()
ctx, cancel := context.WithCancel(bg)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer cancel は呼び忘れないようにしましょう
https://golang.org/pkg/context/

Failing to call the CancelFunc leaks the child and its children until the parent is canceled or the timer fires.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed: 01f9a44

go func() {
defer close(ch)
sc := bufio.NewScanner(in)
for sc.Scan() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bufio.NewScanneros.Stdin を渡しているため、 sc.Scan は標準入力でenterが入力するまでブロックします
そして、下記の箇所でinputのみを待ってしまうために、なにもせず5秒経過したとしても0問正解として終わらず、その後に入力されたひとつ目の入力を受け付けてしまいます
https://github.com/gopherdojo/dojo4/pull/47/files#diff-4d4d5b583e35d4c540d67179051f4406R29

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed: ff5211e

@uobikiemukot uobikiemukot added the kadai3 課題3 label Dec 6, 2018
@uobikiemukot
Copy link
Contributor Author

レビューありがとうございました。
ちょこっと指摘箇所を修正しました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kadai3 課題3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants