From 331e5c36b4721b20a18156505be74e123e58bb55 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 15 Jan 2018 00:34:27 +0100 Subject: expose context --- cmd/eval/main.go | 8 ++++++-- cmd/j1e/main.go | 8 ++++++-- core.go | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/eval/main.go b/cmd/eval/main.go index b9518f3..a5fa686 100644 --- a/cmd/eval/main.go +++ b/cmd/eval/main.go @@ -1,11 +1,15 @@ package main -import "dim13.org/j1" +import ( + "context" + + "dim13.org/j1" +) func main() { vm := j1.New() if err := vm.LoadFile("testdata/j1e.bin"); err != nil { panic(err) } - vm.Run() + vm.Run(context.Background()) } diff --git a/cmd/j1e/main.go b/cmd/j1e/main.go index 65cf626..057e106 100644 --- a/cmd/j1e/main.go +++ b/cmd/j1e/main.go @@ -2,10 +2,14 @@ package main //go:generate file2go -in ../../testdata/j1e.bin -import "dim13.org/j1" +import ( + "context" + + "dim13.org/j1" +) func main() { vm := j1.New() vm.LoadBytes(J1eBin) - vm.Run() + vm.Run(context.Background()) } diff --git a/core.go b/core.go index 5ffe7cb..32f37fb 100644 --- a/core.go +++ b/core.go @@ -54,8 +54,8 @@ func (c *Core) LoadFile(fname string) error { } // Run evaluates content of memory -func (c *Core) Run() { - ctx, cancel := context.WithCancel(context.Background()) +func (c *Core) Run(ctx context.Context) { + ctx, cancel := context.WithCancel(ctx) c.tty = NewConsole(ctx) c.stop = cancel for { -- cgit v1.2.3