From c040ab56364372aeda4d6cff1235fce6f04f2491 Mon Sep 17 00:00:00 2001 From: Jeremy Tregunna Date: Fri, 14 Feb 2025 10:40:04 -0600 Subject: [PATCH] feat: add simple continuation implementation --- continuation.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 continuation.go diff --git a/continuation.go b/continuation.go new file mode 100644 index 0000000..2ab6c80 --- /dev/null +++ b/continuation.go @@ -0,0 +1,24 @@ +package continuation + +type Continuation struct { + result interface{} + err error + doneChan chan struct{} +} + +func NewContinuation() *Continuation { + return &Continuation{ + doneChan: make(chan struct{}), + } +} + +func (c *Continuation) Resume(result interface{}, err error) { + c.result = result + c.err = err + close(c.doneChan) +} + +func (c *Continuation) Wait() (interface{}, error) { + <-c.doneChan + return c.result, c.err +}