Skip to content

Commit

Permalink
refactor(std): time.Sleep -> time.After
Browse files Browse the repository at this point in the history
  • Loading branch information
emil14 committed Sep 21, 2024
1 parent dbc2c85 commit 4b83b68
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions examples/time_after/main.neva
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { time }

flow Main(start) (stop) {
time.After
---
:start -> ($time.second -> after -> :stop)
}
7 changes: 0 additions & 7 deletions examples/time_sleep/main.neva

This file was deleted.

2 changes: 1 addition & 1 deletion internal/runtime/funcs/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func CreatorRegistry() map[string]runtime.FuncCreator {

// time
"time_delay": timeDelay{},
"time_sleep": timeSleep{},
"time_after": timeAfter{},

// strings
"string_at": stringAt{},
Expand Down
4 changes: 2 additions & 2 deletions internal/runtime/funcs/time_sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions std/builtin/bool.neva
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: rename

#extern(eq)
pub flow Eq<T>(actual T, compared T) (res bool)

Expand Down
6 changes: 3 additions & 3 deletions std/time/time.neva
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4b83b68

Please sign in to comment.