Skip to content

Commit

Permalink
doc: udpate example
Browse files Browse the repository at this point in the history
  • Loading branch information
noneback committed Oct 12, 2024
1 parent fe1b04e commit 752b43c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@

# Go workspace file
go.work
*.prof
*.prof
example
51 changes: 48 additions & 3 deletions cmd/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package main
import (
"context"
"fmt"
"log"
"os"
"runtime"

gotaskflow "github.com/noneback/go-taskflow"
)

func main() {
executor := gotaskflow.NewExecutor(uint(runtime.NumCPU()))
executor := gotaskflow.NewExecutor(uint(runtime.NumCPU() - 1))
tf := gotaskflow.NewTaskFlow("G")
A, B, C :=
gotaskflow.NewTask("A", func(ctx *context.Context) {
Expand Down Expand Up @@ -38,8 +40,51 @@ func main() {
C.Succeed(A1)
C.Succeed(B1)

tf.Push(A, B, C)
tf.Push(A1, B1, C1)
subflow := gotaskflow.NewSubflow("sub1", func(sf *gotaskflow.Subflow) {
A2, B2, C2 :=
gotaskflow.NewTask("A2", func(ctx *context.Context) {
fmt.Println("A2")
}),
gotaskflow.NewTask("B2", func(ctx *context.Context) {
fmt.Println("B2")
}),
gotaskflow.NewTask("C2", func(ctx *context.Context) {
fmt.Println("C2")
})
A2.Precede(B2)
C2.Precede(B2)
sf.Push(A2, B2, C2)
})

subflow2 := gotaskflow.NewSubflow("sub2", func(sf *gotaskflow.Subflow) {
A3, B3, C3 :=
gotaskflow.NewTask("A3", func(ctx *context.Context) {
fmt.Println("A3")
}),
gotaskflow.NewTask("B3", func(ctx *context.Context) {
fmt.Println("B3")
}),
gotaskflow.NewTask("C3", func(ctx *context.Context) {
fmt.Println("C3")
// time.Sleep(10 * time.Second)
})
A3.Precede(B3)
C3.Precede(B3)
sf.Push(A3, B3, C3)
})

subflow.Precede(B)
subflow.Precede(subflow2)

tf.Push(A, B, C)
tf.Push(A1, B1, C1, subflow, subflow2)
executor.Run(tf).Wait()
fmt.Println("Print DOT")
if err := gotaskflow.Visualizer.Visualize(tf, os.Stdout); err != nil {
log.Fatal(err)
}
fmt.Println("Print Flamegraph")
if err := executor.Profile(os.Stdout); err != nil {
log.Fatal(err)
}
}
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
)

func main() {
executor := gotaskflow.NewExecutor(runtime.NumCPU() - 1)
executor := gotaskflow.NewExecutor(uint(runtime.NumCPU() - 1))
tf := gotaskflow.NewTaskFlow("G")
A, B, C :=
gotaskflow.NewTask("A", func(ctx *context.Context) {
Expand Down Expand Up @@ -100,19 +100,19 @@ func main() {
subflow.Precede(B)
subflow.Precede(subflow2)

tf := gotaskflow.NewTaskFlow("G")
tf.Push(A, B, C)
tf.Push(A1, B1, C1, subflow, subflow2)
exector.Run(tf).Wait()
executor.Run(tf).Wait()
fmt.Println("Print DOT")
if err := gotaskflow.Visualizer.Visualize(tf, os.Stdout); err != nil {
log.Fatal(err)
}
fmt.Println("Print Flamegraph")
if err :=exector.Profile(os.Stdout);err != nil {
if err := executor.Profile(os.Stdout); err != nil {
log.Fatal(err)
}
}

```
### How to use visualize taskflow
```go
Expand Down

0 comments on commit 752b43c

Please sign in to comment.