Skip to content

Commit

Permalink
clean up fuion signature
Browse files Browse the repository at this point in the history
  • Loading branch information
alob-mtc committed May 1, 2023
1 parent c540ffb commit ec6635e
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions eventloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,38 @@ var (
GlobalEventLoop *eventLoop
)

func Init() {
queue := []func() bool{}
var lock sync.Mutex
func InitGlobalEventLoop() Future {
once.Do(func() {
GlobalEventLoop = &eventLoop{promiseQueue: make([]*Promise, 0)}
})
// TODO: add evnt loop
go func() {
for work := range eventBus {
lock.Lock()
queue = append(queue, *work)
lock.Unlock()
}
}()
queue := []func() bool{}
var lock sync.Mutex
// event loop
go func() {
for work := range eventBus {
lock.Lock()
queue = append(queue, *work)
lock.Unlock()
}
}()

go func() {
for {
n := len(queue)
retry := []func() bool{}
for i := 0; i < n; i++ {
currentWork := queue[i]
go func() {
for {
n := len(queue)
retry := []func() bool{}
for i := 0; i < n; i++ {
currentWork := queue[i]

if done := currentWork(); !done {
retry = append(retry, currentWork)
if done := currentWork(); !done {
retry = append(retry, currentWork)
}
}
lock.Lock()
queue = queue[n:]
queue = append(queue, retry...)
lock.Unlock()
}
lock.Lock()
queue = queue[n:]
queue = append(queue, retry...)
lock.Unlock()
}
}()
}

func GetGlobalEventLoop() Future {
}()
GlobalEventLoop = &eventLoop{promiseQueue: make([]*Promise, 0)}
})
return GlobalEventLoop
}

Expand Down

0 comments on commit ec6635e

Please sign in to comment.