From 4b83b6805c85511bed585cb57f779e8da943ad2e Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Sat, 21 Sep 2024 20:31:07 +0500 Subject: [PATCH] refactor(std): time.Sleep -> time.After --- examples/{time_sleep => time_after}/e2e_test.go | 2 +- examples/time_after/main.neva | 7 +++++++ examples/time_sleep/main.neva | 7 ------- internal/runtime/funcs/registry.go | 2 +- internal/runtime/funcs/time_sleep.go | 4 ++-- std/builtin/bool.neva | 2 -- std/time/time.neva | 6 +++--- 7 files changed, 14 insertions(+), 16 deletions(-) rename examples/{time_sleep => time_after}/e2e_test.go (90%) create mode 100644 examples/time_after/main.neva delete mode 100644 examples/time_sleep/main.neva diff --git a/examples/time_sleep/e2e_test.go b/examples/time_after/e2e_test.go similarity index 90% rename from examples/time_sleep/e2e_test.go rename to examples/time_after/e2e_test.go index c1431cbb..10d28964 100644 --- a/examples/time_sleep/e2e_test.go +++ b/examples/time_after/e2e_test.go @@ -17,7 +17,7 @@ func Test(t *testing.T) { require.NoError(t, err) defer os.Chdir(wd) - cmd := exec.Command("neva", "run", "time_sleep") + cmd := exec.Command("neva", "run", "time_after") before := time.Now() out, err := cmd.CombinedOutput() diff --git a/examples/time_after/main.neva b/examples/time_after/main.neva new file mode 100644 index 00000000..a1d4d3e2 --- /dev/null +++ b/examples/time_after/main.neva @@ -0,0 +1,7 @@ +import { time } + +flow Main(start) (stop) { + time.After + --- + :start -> ($time.second -> after -> :stop) +} diff --git a/examples/time_sleep/main.neva b/examples/time_sleep/main.neva deleted file mode 100644 index 6ddbd719..00000000 --- a/examples/time_sleep/main.neva +++ /dev/null @@ -1,7 +0,0 @@ -import { time } - -flow Main(start) (stop) { - time.Sleep - --- - :start -> ($time.second -> sleep -> :stop) -} diff --git a/internal/runtime/funcs/registry.go b/internal/runtime/funcs/registry.go index 399a36fe..82e64ac8 100644 --- a/internal/runtime/funcs/registry.go +++ b/internal/runtime/funcs/registry.go @@ -75,7 +75,7 @@ func CreatorRegistry() map[string]runtime.FuncCreator { // time "time_delay": timeDelay{}, - "time_sleep": timeSleep{}, + "time_after": timeAfter{}, // strings "string_at": stringAt{}, diff --git a/internal/runtime/funcs/time_sleep.go b/internal/runtime/funcs/time_sleep.go index 48fca116..4977e4ce 100644 --- a/internal/runtime/funcs/time_sleep.go +++ b/internal/runtime/funcs/time_sleep.go @@ -7,9 +7,9 @@ import ( "github.com/nevalang/neva/internal/runtime" ) -type timeSleep struct{} +type timeAfter struct{} -func (timeSleep) Create(io runtime.IO, _ runtime.Msg) (func(ctx context.Context), error) { +func (timeAfter) Create(io runtime.IO, _ runtime.Msg) (func(ctx context.Context), error) { durIn, err := io.In.Single("dur") if err != nil { return nil, err diff --git a/std/builtin/bool.neva b/std/builtin/bool.neva index a8f2da81..e321916e 100644 --- a/std/builtin/bool.neva +++ b/std/builtin/bool.neva @@ -1,5 +1,3 @@ -// TODO: rename - #extern(eq) pub flow Eq(actual T, compared T) (res bool) diff --git a/std/time/time.neva b/std/time/time.neva index db662f03..3dfb931f 100644 --- a/std/time/time.neva +++ b/std/time/time.neva @@ -8,11 +8,11 @@ pub const second Duration = 1000000000 pub const minute Duration = 60000000000 pub const hour Duration = 3600000000000 -// Sleep blocks the flow for (at least) provided duration. +// After blocks the flow for (at least) provided duration. // When enough time has passed, it sends a signal to its output port. // If you want to delay a message, use Delay instead. -#extern(time_sleep) -pub flow Sleep(dur Duration) (sig) +#extern(time_after) +pub flow After(dur Duration) (sig) // Delay waits for both dur and data messages. // As soon as they both arrive it starts waiting