All checks were successful
Build / build (push) Successful in 2m32s
- call now supports calling invokables by string - call now takes as arguments a listable of positional args, and a hashable of keyword args - added strs:split, strs:join, and strs:has-prefix - added new lists module with lists:first - added time:sleep
43 lines
717 B
Go
43 lines
717 B
Go
package builtins
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
"ucl.lmika.dev/ucl"
|
|
)
|
|
|
|
func Time() ucl.Module {
|
|
return ucl.Module{
|
|
Name: "time",
|
|
Builtins: map[string]ucl.BuiltinHandler{
|
|
"from-unix": timeFromUnix,
|
|
"sleep": timeSleep,
|
|
},
|
|
}
|
|
}
|
|
|
|
func timeFromUnix(ctx context.Context, args ucl.CallArgs) (any, error) {
|
|
var ux int
|
|
|
|
if err := args.Bind(&ux); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return time.Unix(int64(ux), 0).UTC(), nil
|
|
}
|
|
|
|
func timeSleep(ctx context.Context, args ucl.CallArgs) (any, error) {
|
|
var secs int
|
|
|
|
if err := args.Bind(&secs); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
select {
|
|
case <-time.After(time.Duration(secs) * time.Second):
|
|
return nil, nil
|
|
case <-ctx.Done():
|
|
return nil, ctx.Err()
|
|
}
|
|
}
|