package main
import (
"context"
"flag"
"os"
"time"
amtest "github.com/pancsta/asyncmachine-go/internal/testing"
amhelp "github.com/pancsta/asyncmachine-go/pkg/helpers"
am "github.com/pancsta/asyncmachine-go/pkg/machine"
"github.com/pancsta/asyncmachine-go/pkg/rpc"
ssrpc "github.com/pancsta/asyncmachine-go/pkg/rpc/states"
"github.com/pancsta/asyncmachine-go/pkg/telemetry"
"github.com/pancsta/asyncmachine-go/tools/debugger"
"github.com/pancsta/asyncmachine-go/tools/debugger/server"
ssdbg "github.com/pancsta/asyncmachine-go/tools/debugger/states"
)
func main() {
ctx , cancel := context .WithCancel (context .Background ())
defer cancel ()
amDbgAddr := os .Getenv (telemetry .EnvAmDbgAddr )
logLvl := am .EnvLogLevel ("" )
serverAddr := flag .String ("server-addr" , "" ,
"Addr of the debugger server (opt)" )
workerAddr := flag .String ("worker-addr" , amtest .WorkerRpcAddr ,
"Addr of the rpc worker" )
flag .Parse ()
os .Setenv (amhelp .EnvAmLogFile , "1" )
dbg , err := amtest .NewDbgWorker (true , debugger .Opts {
AddrRpc : *serverAddr ,
})
if err != nil {
panic (err )
}
s , err := rpc .NewServer (ctx , *workerAddr , "worker" , dbg .Mach , nil )
if err != nil {
panic (err )
}
amhelp .MachDebug (s .Mach , amDbgAddr , logLvl , false ,
amhelp .SemConfig (true ))
defer func () {
if amDbgAddr != "" {
time .Sleep (100 * time .Millisecond )
}
}()
if *serverAddr != "" {
go server .StartRpc (dbg .Mach , *serverAddr , nil , nil , false )
}
readyCtx , cancel := context .WithTimeout (ctx , 3 *time .Second )
defer cancel ()
s .Start ()
select {
case <- s .Mach .WhenErr (readyCtx ):
err := s .Mach .Err ()
if readyCtx .Err () != nil {
err = readyCtx .Err ()
}
panic (err )
case <- s .Mach .When1 (ssrpc .ServerStates .RpcReady , readyCtx ):
}
select {
case <- dbg .Mach .WhenDisposed ():
case <- dbg .Mach .WhenNot1 (ssdbg .Start , nil ):
dbg .Dispose ()
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .