Skip to content

Commit e809fb5

Browse files
committed
ctx added
1 parent f4cd29a commit e809fb5

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ req := busi.BusiReq{Amount: 30, TransInResult: ""}
9292
data, err := proto.Marshal(&req)
9393

9494
// Execute workflow
95-
err = workflow.Execute(wfName, shortuuid.New(), data)
95+
_, err = workflow.ExecuteCtx(wfName, shortuuid.New(), data)
9696
logger.Infof("result of workflow.Execute is: %v", err)
9797

9898
```

client/workflow/workflow.go

+12-19
Original file line numberDiff line numberDiff line change
@@ -53,39 +53,32 @@ func Register2(name string, handler WfFunc2, custom ...func(wf *Workflow)) error
5353
return defaultFac.register(name, handler, custom...)
5454
}
5555

56-
// Execute is the same as ExecuteCtx, but with context.Background
57-
func Execute(name string, gid string, data []byte) error {
58-
return ExecuteCtx(context.Background(), name, gid, data)
59-
}
60-
6156
// ExecuteCtx will execute a workflow with the gid and specified params
6257
// if the workflow with the gid does not exist, then create a new workflow and execute it
6358
// if the workflow with the gid exists, resume to execute it
64-
func ExecuteCtx(ctx context.Context, name string, gid string, data []byte) error {
65-
_, err := defaultFac.execute(ctx, name, gid, data)
59+
func ExecuteCtx(ctx context.Context, name string, gid string, data []byte) ([]byte, error) {
60+
return defaultFac.execute(ctx, name, gid, data)
61+
}
62+
63+
// Execute is the same as ExecuteCtx, but with context.Background
64+
// Deprecated: use ExecuteCtx instaead
65+
func Execute(name string, gid string, data []byte) error {
66+
_, err := ExecuteCtx(context.Background(), name, gid, data)
6667
return err
6768
}
6869

6970
// Execute2 is the same as Execute, but workflow func can return result
71+
// Deprecated: use ExecuteCtx instaead
7072
func Execute2(name string, gid string, data []byte) ([]byte, error) {
71-
return Execute2Ctx(context.Background(), name, gid, data)
72-
}
73-
74-
// Execute2Ctx is the same as Execute2, but with context.Background
75-
func Execute2Ctx(ctx context.Context, name string, gid string, data []byte) ([]byte, error) {
76-
return defaultFac.execute(ctx, name, gid, data)
73+
return ExecuteCtx(context.Background(), name, gid, data)
7774
}
7875

7976
// ExecuteByQS is like Execute, but name and gid will be obtained from qs
77+
// Deprecated: use ExecuteCtx instaead
8078
func ExecuteByQS(qs url.Values, body []byte) error {
81-
return ExecuteByQSCtx(context.Background(), qs, body)
82-
}
83-
84-
// ExecuteByQSCtx is the same as ExecuteByQS, but with context.Background
85-
func ExecuteByQSCtx(ctx context.Context, qs url.Values, body []byte) error {
8679
name := qs.Get("op")
8780
gid := qs.Get("gid")
88-
_, err := defaultFac.execute(ctx, name, gid, body)
81+
_, err := ExecuteCtx(context.Background(), name, gid, body)
8982
return err
9083
}
9184

helper/README-en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ req := busi.BusiReq{Amount: 30, TransInResult: ""}
9292
data, err := proto.Marshal(&req)
9393

9494
// Execute workflow
95-
err = workflow.Execute(wfName, shortuuid.New(), data)
95+
_, err = workflow.ExecuteCtx(wfName, shortuuid.New(), data)
9696
logger.Infof("result of workflow.Execute is: %v", err)
9797

9898
```

0 commit comments

Comments
 (0)