From 565751db4e5b8370c0a05d1998a91e6e20a19bb4 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 24 Jan 2018 01:59:13 +0100 Subject: remove context --- console/console.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'console/console.go') diff --git a/console/console.go b/console/console.go index 4fe9680..577e021 100644 --- a/console/console.go +++ b/console/console.go @@ -1,7 +1,6 @@ package console import ( - "context" "fmt" "io" "os" @@ -11,36 +10,38 @@ type Console struct { r io.Reader w io.Writer ich, och chan uint16 + done chan struct{} } -func New(ctx context.Context) *Console { +func New() *Console { c := &Console{ - r: os.Stdin, - w: os.Stdout, - ich: make(chan uint16, 1), - och: make(chan uint16, 1), + r: os.Stdin, + w: os.Stdout, + ich: make(chan uint16, 1), + och: make(chan uint16, 1), + done: make(chan struct{}), } - go c.read(ctx) - go c.write(ctx) + go c.read() + go c.write() return c } -func (c *Console) read(ctx context.Context) { +func (c *Console) read() { var v uint16 for { fmt.Fscanf(c.r, "%c", &v) select { - case <-ctx.Done(): + case <-c.done: return case c.ich <- v: } } } -func (c *Console) write(ctx context.Context) { +func (c *Console) write() { for { select { - case <-ctx.Done(): + case <-c.done: return case v := <-c.och: fmt.Fprintf(c.w, "%c", v) @@ -51,3 +52,4 @@ func (c *Console) write(ctx context.Context) { func (c *Console) Read() uint16 { return <-c.ich } func (c *Console) Write(v uint16) { c.och <- v } func (c *Console) Len() uint16 { return uint16(len(c.ich)) } +func (c *Console) Stop() { close(c.done) } -- cgit v1.2.3