aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorSangTran-127 <tranquangsang12.7@gmail.com>2026-08-08 17:24:01 +0700
committerSangTran-127 <tranquangsang12.7@gmail.com>2026-08-08 17:24:01 +0700
commit0958e46c3651f2c8b6d76bcffbd8820063647d59 (patch)
tree1e917ed409eddc0b3c29fd602e551778c96c8dc6 /main.go
parentacc0b6fbaace61a3befd7f726f9d80fb69391126 (diff)
downloadgoflink-0958e46c3651f2c8b6d76bcffbd8820063647d59.tar.gz
goflink-0958e46c3651f2c8b6d76bcffbd8820063647d59.zip
refactor: add context support to transport operators and runtime task management
Diffstat (limited to 'main.go')
-rw-r--r--main.go40
1 files changed, 38 insertions, 2 deletions
diff --git a/main.go b/main.go
index 25792c1..806c1ed 100644
--- a/main.go
+++ b/main.go
@@ -1,13 +1,49 @@
package main
import (
+ "context"
"fmt"
+ "strconv"
+
"goflink/core"
- "unsafe"
+ "goflink/runtime"
+ "goflink/transport"
)
func main() {
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ source := make(chan core.StreamRecord[int])
+ mid := make(chan core.StreamRecord[int])
+ sink := make(chan core.StreamRecord[string])
+
+ // x*10, then render as text
+ mapped := runtime.RunTask(ctx,
+ transport.NewLocalReceiveChannel(source),
+ transport.NewLocalEmitChannel(mid),
+ core.NewMapOperator(func(in int) (int, error) { return in * 10, nil }),
+ )
+ printed := runtime.RunTask(ctx,
+ transport.NewLocalReceiveChannel(mid),
+ transport.NewLocalEmitChannel(sink),
+ core.NewMapOperator(func(in int) (string, error) { return "v=" + strconv.Itoa(in), nil }),
+ )
+
+ go func() {
+ defer close(source)
+ for i := 1; i <= 5; i++ {
+ source <- core.NewDataRecord("k", i, 0)
+ }
+ }()
- fmt.Printf("GoodRecord Size: %d bytes\n", unsafe.Sizeof(core.StreamRecord[int]{}))
+ for record := range sink {
+ fmt.Println(record.Value)
+ }
+ for _, errCh := range []<-chan error{mapped, printed} {
+ if err := <-errCh; err != nil {
+ fmt.Println("task failed:", err)
+ }
+ }
}