go-judge/cmd/executorserver/waiter.go
criyle 7951f37bd4 Implements the draft executor server
- Add new command executorserver as the draft executor server
- Move shared pool logic into /pkg/pool
2020-03-04 02:12:26 -05:00

30 lines
456 B
Go

package main
import (
"context"
"time"
"github.com/criyle/go-judge/pkg/envexec"
)
type waiter struct {
timeLimit time.Duration
realTimeLimit time.Duration
}
func (w *waiter) Wait(ctx context.Context, u envexec.CPUUsager) bool {
if w.realTimeLimit < w.timeLimit {
w.realTimeLimit = w.timeLimit
}
timer := time.NewTimer(w.realTimeLimit)
defer timer.Stop()
select {
case <-ctx.Done():
return false
case <-timer.C:
return true
}
}