Skip to content

Commit

Permalink
Add example for ResultWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
hibiken committed Jan 31, 2022
1 parent dff2e3a commit 349f4c5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package asynq_test

import (
"context"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -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
}

0 comments on commit 349f4c5

Please sign in to comment.