40 lines
658 B
Go
40 lines
658 B
Go
|
package api
|
||
|
|
||
|
import "time"
|
||
|
|
||
|
var state State
|
||
|
|
||
|
// unexported function(s)
|
||
|
func runBlocking(function string) bool {
|
||
|
return run(function, true)
|
||
|
}
|
||
|
|
||
|
func run(function string, blocking bool) bool {
|
||
|
if state.blocking {
|
||
|
return false
|
||
|
}
|
||
|
state.functionName = function
|
||
|
state.blocking = blocking
|
||
|
timestamp := time.Now()
|
||
|
state.startTime = timestamp
|
||
|
state.stopTime = timestamp
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
func getRunning() State {
|
||
|
return state
|
||
|
}
|
||
|
|
||
|
func finish() time.Duration {
|
||
|
state.stopTime = time.Now()
|
||
|
return state.stopTime.Sub(state.startTime)
|
||
|
}
|
||
|
|
||
|
// struct(s)
|
||
|
type State struct {
|
||
|
functionName string
|
||
|
blocking bool
|
||
|
startTime time.Time
|
||
|
stopTime time.Time
|
||
|
}
|