Files
hatchet/pkg/examples/streaming/consumer/main.go
Mohammed Nafees c86a65bb0f Add new streaming support to Go SDK (#1955)
* add Go SDK streaming support

* make docs changes for go sdk streaming

* fix git lfs warning

* streaming go example

* fix lint

* fix auto generated snip

* revert poetry lock changes

* some cleanup
2025-07-11 18:00:30 +02:00

42 lines
804 B
Go

package main
import (
"context"
"fmt"
"log"
"github.com/hatchet-dev/hatchet/examples/go/streaming/shared"
v1 "github.com/hatchet-dev/hatchet/pkg/v1"
)
// > Consume
func main() {
hatchet, err := v1.NewHatchetClient()
if err != nil {
log.Fatalf("Failed to create Hatchet client: %v", err)
}
ctx := context.Background()
streamingWorkflow := shared.StreamingWorkflow(hatchet)
workflowRun, err := streamingWorkflow.RunNoWait(ctx, shared.StreamTaskInput{})
if err != nil {
log.Fatalf("Failed to run workflow: %v", err)
}
id := workflowRun.RunId()
stream, err := hatchet.Runs().SubscribeToStream(ctx, id)
if err != nil {
log.Fatalf("Failed to subscribe to stream: %v", err)
}
for content := range stream {
fmt.Print(content)
}
fmt.Println("\nStreaming completed!")
}
// !!