Skip to content

Commit

Permalink
Tidy up the coroutine after response is generated
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Jun 17, 2024
1 parent e593364 commit 975e2ba
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions coroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ func (c *GenericCoroutine[I, O]) Run(ctx context.Context, req Request) Response
coro.Send(CoroS{directive: pollResult})
}

// Tidy up the coroutine when returning.
defer func() {
if !coro.Done() {
coro.Stop()
coro.Next()
}
}()

// Run the coroutine until it yields or returns.
if coro.Next() {
// The coroutine yielded and is now paused.
Expand Down

0 comments on commit 975e2ba

Please sign in to comment.