kadai3-1 yoheimiyamoto - #46
Open
yoheimiyamoto wants to merge 5 commits into
Open
Conversation
yoheimiyamoto
commented
Nov 25, 2018
- 標準出力に英単語を出す(出すものは自由)
- 標準入力から1行受け取る
- 制限時間内に何問解けたか表示する
mizkei
reviewed
Nov 26, 2018
| // words -> 出題するワード一覧 | ||
| func Play(r io.Reader, w io.Writer, words []string) { | ||
| inputCh := make(chan string) | ||
| inputDone := make(chan struct{}, 1) |
| } | ||
| close(inputDone) // inputのチャネルを閉じる | ||
| fmt.Fprintln(w, "タイムアウト。ゲーム終了") | ||
| fmt.Println(s.Result()) |
There was a problem hiding this comment.
ここまで w io.Writer にのみ利用してきているので、ここも os.Stdout ではなく w に書き込んだほうがテストしやすさ的にも良いと思います
| fmt.Fprintln(w, "不正解!") | ||
| s.addIncorrect() | ||
| } | ||
| case <-time.After(5 * time.Second): |
There was a problem hiding this comment.
一つのワード入力の 制限時間5秒 であるならばよいのですが、ゲーム自体の制限時間であれば、このforの外で time.After を実行しておかないとforに入るたびに5秒からカウントしてしまいます
| } | ||
| }() | ||
|
|
||
| // 上記を以下のようにgoroutine使わずに記述するとゲームがフリーズしてしまう理由が理解できていないです。 |
There was a problem hiding this comment.
doneがcloseされるまでブロックすることになるので、inputの実行箇所でとまることになります
| }() | ||
|
|
||
| // ゲームが終了した場合、inputも終了させる。 | ||
| go func() { |
There was a problem hiding this comment.
goroutineとして実行しているので、この処理自体ほとんど意味がなさそうです
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.