Skip to content

Commit

Permalink
fix(examples:wait_group): shared receiver; fix(runtime:funcs): sendin…
Browse files Browse the repository at this point in the history
…g nil as msg caused panic;
  • Loading branch information
emil14 committed Oct 3, 2024
1 parent 1201548 commit 1413800
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 25 deletions.
16 changes: 8 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"version": "0.2.0",
"configurations": [
// {
// "name": "Debug Compiled Go",
// "type": "go",
// "request": "launch",
// "mode": "auto",
// "program": "${workspaceFolder}/dist/main.go",
// "cwd": "${workspaceFolder}/dist"
// },
{
"name": "Debug Compiled Go",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/examples/dist/main.go",
"cwd": "${workspaceFolder}/examples"
},
{
"name": "RUN",
"type": "go",
Expand Down
23 changes: 12 additions & 11 deletions examples/wait_group/main.neva
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { sync }

flow Main(start) (stop) {
wg sync.WaitGroup
Println
---
:start -> [
('Hello' -> println -> wg:sig),
('Neva' -> println -> wg:sig),
('World!' -> println -> wg:sig)
]
3 -> wg:count
wg -> :stop
}
p1 Println, p2 Println, p3 Println
wg sync.WaitGroup
---
:start -> [
('Hello' -> p1),
('Neva' -> p2),
('World!' -> p3)
]
[p1, p2, p3] -> wg:sig
3 -> wg:count
wg -> :stop
}
1 change: 0 additions & 1 deletion internal/compiler/backend/golang/tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func main() {
if err != nil {
panic(err)
}
defer func() {
if err := close(); err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/funcs/time_sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (timeAfter) Create(io runtime.IO, _ runtime.Msg) (func(ctx context.Context)

time.Sleep(time.Duration(durMsg.Int()))

if !sigOut.Send(ctx, nil) {
if !sigOut.Send(ctx, emptyStruct()) {
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/funcs/unwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (unwrap) Create(io runtime.IO, _ runtime.Msg) (func(ctx context.Context), e
}

if dataMsg == nil {
if !noneOut.Send(ctx, nil) {
if !noneOut.Send(ctx, emptyStruct()) {
return
}
continue
Expand Down
4 changes: 4 additions & 0 deletions internal/runtime/funcs/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ func streamItem(data runtime.Msg, idx int64, last bool) runtime.StructMsg {
[]runtime.Msg{data, runtime.NewIntMsg(idx), runtime.NewBoolMsg(last)},
)
}

func emptyStruct() runtime.StructMsg {
return emptyStruct()

Check failure on line 27 in internal/runtime/funcs/utils.go

View workflow job for this annotation

GitHub Actions / lint

SA5007: infinite recursive call (staticcheck)
}
2 changes: 1 addition & 1 deletion internal/runtime/funcs/wait_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (waitGroup) Handle(
}
}

if !sigOut.Send(ctx, nil) {
if !sigOut.Send(ctx, emptyStruct()) {
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/funcs/write_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c writeAll) Create(rio runtime.IO, _ runtime.Msg) (func(ctx context.Contex
continue
}

if !sig.Send(ctx, nil) {
if !sig.Send(ctx, emptyStruct()) {
return
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/runtime/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func (d *DebugInterceptor) Received(receiver PortSlotAddr, msg Msg) Msg {
}

func (d DebugInterceptor) formatMsg(msg Msg) string {
if msg.Str() != "" {
return fmt.Sprintf("%q", msg.Str())
}
return fmt.Sprint(msg)
}

Expand Down
5 changes: 4 additions & 1 deletion internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ func Run(ctx context.Context, prog Program, registry map[string]FuncCreator) err
close(funcsFinished)
}()

prog.Start.Send(ctx, &baseMsg{}) // lock until some node receive
prog.Start.Send(
ctx,
NewStructMsg(nil, nil),
)

<-funcsFinished

Expand Down

0 comments on commit 1413800

Please sign in to comment.