-
Notifications
You must be signed in to change notification settings - Fork 6
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
dojo7 [課題3-1] タイピングゲームを作ろう #33
base: kadai2-asuke-yasukuni
Are you sure you want to change the base?
Conversation
Input() <-chan string | ||
} | ||
|
||
type Reader struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こうかいしなくても良さそう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確かに
|
||
type Reader struct{} | ||
|
||
func (r *Reader) Input() <-chan string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty structの場合はレシーバポインタにしちゃうとポインタ分スタックにメモリを確保するので func (Reader) Input <-chan string
のようにしておくと良さそう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
おお、なるほど、そういう書き方が。
|
||
go func() { | ||
s := bufio.NewScanner(os.Stdin) | ||
for s.Scan() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
エラー処理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あー。 s.Err() で取れるのか。
|
||
type Writer struct{} | ||
|
||
func (w Writer) Output(outputText string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (Writer)
func (r *Reader) Input() <-chan string { | ||
ch := make(chan string) | ||
|
||
go func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
タイムアウトした際にこのゴールーチンが終了しなさそう。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
おふ。。
課題3-2が重いため、かなり簡素な感じにしました。
インターフェースの概念に慣れてないせいで、チャネルが絡むテストを書くのが以外に難しかったです。
最終的には割とちゃんと書けた気がします(気がするだけかもしれない)。
回答