1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/stdlib/utils/utils.go

46 lines
867 B
Go
Raw Normal View History

2018-09-18 22:42:38 +02:00
package utils
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
2018-09-28 06:28:33 +02:00
"github.com/MontFerret/ferret/pkg/runtime/logging"
2018-09-18 22:42:38 +02:00
"github.com/MontFerret/ferret/pkg/runtime/values"
"time"
)
func Wait(_ context.Context, inputs ...core.Value) (core.Value, error) {
err := core.ValidateArgs(inputs, 1, 1)
2018-09-18 22:42:38 +02: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
}
2018-09-28 06:28:33 +02:00
func Log(ctx context.Context, inputs ...core.Value) (core.Value, error) {
2018-09-18 22:42:38 +02:00
args := make([]interface{}, 0, len(inputs)+1)
for _, input := range inputs {
args = append(args, input)
}
2018-09-29 03:04:16 +02:00
logger := logging.FromContext(ctx)
2018-09-28 06:28:33 +02:00
logger.Print(args...)
2018-09-18 22:42:38 +02:00
return values.None, nil
}