Add MainRunnable interface for locking to the main thread
This commit is contained in:
35
phases.go
35
phases.go
@@ -228,6 +228,41 @@ func (this *environment) phase60Initialization() bool {
|
||||
}
|
||||
|
||||
func (this *environment) phase70Running() bool {
|
||||
for actor := range this.All() {
|
||||
if actor, ok := actor.(MainRunnable); ok {
|
||||
this.main = actor
|
||||
}
|
||||
}
|
||||
|
||||
result := make(chan bool)
|
||||
go func() {
|
||||
result <- this.phase70RunningBody()
|
||||
if this.main != nil {
|
||||
shutdownCtx, done := context.WithTimeout(
|
||||
context.Background(),
|
||||
defaul(this.timing.shutdownTimeout.Load(),
|
||||
defaultShutdownTimeout))
|
||||
defer done()
|
||||
this.main.ShutdownMain(shutdownCtx)
|
||||
}
|
||||
}()
|
||||
|
||||
if this.main != nil {
|
||||
mainActor := this.main.(Actor)
|
||||
if this.Verb() { log.Printf("(i) (70) binding %s to main thread", mainActor.Type()) }
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
err := this.main.RunMain()
|
||||
if err != nil {
|
||||
log.Printf("XXX [%s] main thread failed: %v", mainActor.Type(), err)
|
||||
}
|
||||
if this.Verb() { log.Printf("(i) (70) main thread exited") }
|
||||
}
|
||||
|
||||
return <- result
|
||||
}
|
||||
|
||||
func (this *environment) phase70RunningBody() bool {
|
||||
defer this.Done(nil)
|
||||
if this.Verb() { log.Println("... (70) starting up") }
|
||||
this.running.Store(true)
|
||||
|
||||
Reference in New Issue
Block a user