diff --git a/example_test.go b/example_test.go index c2909a2..333236d 100644 --- a/example_test.go +++ b/example_test.go @@ -5,6 +5,7 @@ package asynq_test import ( + "context" "fmt" "log" "os" @@ -113,3 +114,20 @@ func ExampleParseRedisURI() { // localhost:6379 // 10 } + +func ExampleResultWriter() { + // ResultWriter is only accessible in Handler. + h := func(ctx context.Context, task *asynq.Task) error { + // .. do task processing work + + res := []byte("task result data") + n, err := task.ResultWriter().Write(res) // implements io.Writer + if err != nil { + return fmt.Errorf("failed to write task result: %v", err) + } + log.Printf(" %d bytes written", n) + return nil + } + + _ = h +}