2018-09-18 22:42:38 +02:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-10-14 19:06:27 +02:00
|
|
|
"time"
|
|
|
|
|
2018-09-18 22:42:38 +02:00
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
|
|
)
|
|
|
|
|
2018-10-14 19:06:27 +02:00
|
|
|
// Wait pauses the execution for a given period.
|
2019-03-19 22:17:05 +02:00
|
|
|
// @param timeout (Float|Int) - Number value which indicates for how long to stop an execution.
|
|
|
|
func Wait(_ context.Context, args ...core.Value) (core.Value, error) {
|
|
|
|
err := core.ValidateArgs(args, 1, 1)
|
2018-09-18 22:42:38 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.None, nil
|
|
|
|
}
|
|
|
|
|
2019-05-19 18:12:11 +02:00
|
|
|
arg := values.ToInt(args[0])
|
2018-09-18 22:42:38 +02:00
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * time.Duration(arg))
|
|
|
|
|
|
|
|
return values.None, nil
|
|
|
|
}
|