2018-09-18 16:42:38 -04:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-10-14 20:06:27 +03:00
|
|
|
"time"
|
|
|
|
|
2018-09-18 16:42:38 -04:00
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
|
|
)
|
|
|
|
|
2018-10-14 20:06:27 +03:00
|
|
|
// Wait pauses the execution for a given period.
|
|
|
|
// @param timeout (Int) - Integer value indication for how long to pause.
|
2018-09-25 11:43:58 -04:00
|
|
|
func Wait(_ context.Context, inputs ...core.Value) (core.Value, error) {
|
2018-09-21 20:36:33 -04:00
|
|
|
err := core.ValidateArgs(inputs, 1, 1)
|
2018-09-18 16:42:38 -04:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.None, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
arg := values.ZeroInt
|
|
|
|
|
|
|
|
err = core.ValidateType(inputs[0], core.IntType)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.None, err
|
|
|
|
}
|
|
|
|
|
|
|
|
arg = inputs[0].(values.Int)
|
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * time.Duration(arg))
|
|
|
|
|
|
|
|
return values.None, nil
|
|
|
|
}
|