mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-25 07:12:17 +08:00
Add example for ResultWriter
This commit is contained in:
parent
dff2e3a336
commit
349f4c50fb
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user