From 4ec4ed1fcebfb25508b65fb3a4ff816bb872a9ad Mon Sep 17 00:00:00 2001 From: Akinlua Bolamigbe Date: Sat, 18 Mar 2023 17:37:14 +0100 Subject: [PATCH] fixed memeory bug --- eventloop.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/eventloop.go b/eventloop.go index 90716cd..f1c566c 100644 --- a/eventloop.go +++ b/eventloop.go @@ -98,22 +98,17 @@ func (e *eventLoop) Main(fn func()) { } func (e *eventLoop) awaitAll() { - select { - case <-time.After(time.Second * 1): - case <-e.signal: + for { n := len(e.promiseQueue) for i := n - 1; i >= 0; i-- { p := e.promiseQueue[i] if p.handler { <-p.done + //TODO clean up memory (promise) } - if currentN := int(atomic.LoadUint64(&e.size)); i == 0 && currentN > n { - // process fresh promise - e.awaitAll() + if currentN := int(atomic.LoadUint64(&e.size)); i == 0 && !(currentN > n) && !e.keepAlive { + break } } } - if e.keepAlive { - e.awaitAll() - } }