mirror of
https://github.com/wahyd4/forego.git
synced 2026-08-08 21:01:01 +10:00
Simplify Forego.startProcess (#79)
* Remove unnecessary return * Simplify method Forego.startProcess We need to call f.teardown.Fall() only when a process has finished and restart is disabled. When f.teardown.Barrier() is closed, it’s unnecessary to call f.teardown.Fall() because we know the barrier is already closed. * Don’t wait twice on finished The select has two cases. In the first case, we wait on finished. We don’t need to wait on finished a second time since we already know that finished is closed. This is the reason why we moved the defer statement at the beginning of the second case. * This goroutine doesn’t need to block until the process has finished
This commit is contained in:
committed by
David Dollar
parent
9bc72ddb1f
commit
9c1bbd7d26
@@ -163,17 +163,12 @@ func (f *Forego) startProcess(idx, procNum int, proc ProcfileEntry, env Env, of
|
||||
go func() {
|
||||
defer f.wg.Done()
|
||||
|
||||
// Prevent goroutine from exiting before process has finished.
|
||||
defer func() { <-finished }()
|
||||
if !flagRestart {
|
||||
defer f.teardown.Fall()
|
||||
}
|
||||
|
||||
select {
|
||||
case <-finished:
|
||||
if flagRestart {
|
||||
f.startProcess(idx, procNum, proc, env, of)
|
||||
return
|
||||
} else {
|
||||
f.teardown.Fall()
|
||||
}
|
||||
|
||||
case <-f.teardown.Barrier():
|
||||
|
||||
Reference in New Issue
Block a user