Skip to content

Commit

Permalink
fixed a memory bug
Browse files Browse the repository at this point in the history
  • Loading branch information
alob-mtc committed Mar 18, 2023
1 parent 4ec4ed1 commit 993274e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions eventloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type eventLoop struct {
size uint64
signal chan struct{}
keepAlive bool
sync sync.Mutex
}

func (e *eventLoop) Await(currentP *Promise) (interface{}, error) {
Expand Down Expand Up @@ -99,7 +100,9 @@ func (e *eventLoop) Main(fn func()) {

func (e *eventLoop) awaitAll() {
for {
e.sync.Lock()
n := len(e.promiseQueue)
e.sync.Unlock()
for i := n - 1; i >= 0; i-- {
p := e.promiseQueue[i]
if p.handler {
Expand Down
2 changes: 2 additions & 0 deletions promise.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ func (e *eventLoop) newPromise(rev <-chan interface{}, errChan chan error) *Prom
defer close(e.signal)
}
currentP := &Promise{id: atomic.AddUint64(&e.size, 1), rev: rev, errChan: errChan, done: make(chan struct{}), err: make(chan struct{})}
e.sync.Lock()
e.promiseQueue = append(e.promiseQueue, currentP)
e.sync.Unlock()
return currentP
}

Expand Down

0 comments on commit 993274e

Please sign in to comment.