You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-59Lines changed: 43 additions & 59 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@
4
4
5
5
Borrows heavily from [Temporal](https://github.com/temporalio/temporal) (and since it's a fork also [Cadence](https://github.com/uber/cadence)) as well as [DTFx](https://github.com/Azure/durabletask).
6
6
7
-
Note on go1.18 generics: many of the `Get(...)` operations will become easier with generics, an ongoing exploration is happening in branch [go118](https://github.com/cschleiden/go-workflows/tree/go118).
On Go support: the current version of the library requires **Go 1.18** or later. There is a version that doesn't require generics and relies more on `interface{}` instead, but I think the improved type safety is worth not supporting a version of Go before 1.18 for now.
11
+
12
12
## Simple example
13
13
14
14
### Workflow
@@ -17,15 +17,15 @@ Workflows are written in Go code. The only exception is they must not use any of
From a workflow, call `workflow.ExecuteActivity` to execute an activity. The call returns a `Future` you can await to get the result or any error it might return.
Sometimes scheduling an activity is too much overhead for a simple side effect. For those scenarios you can use `workflow.SideEffect`. You can pass a func which will be executed only once inline with its result being recorded in the history. Subsequent executions of the workflow will return the previously recorded result.
return"", errors.Wrap(err, "could not get activity result")
296
293
}
297
294
@@ -320,19 +317,17 @@ if err != nil {
320
317
Due its non-deterministic behavior you must not use a `select` statement in workflows. Instead you can use the provided `workflow.Select` function. It blocks until one of the provided cases is ready. Cases are evaluated in the order passed to `Select.
321
318
322
319
```go
323
-
var f1 workflow.Future
324
-
var c workflow.Channel
320
+
var f1 workflow.Future[int]
321
+
var c workflow.Channel[int]
325
322
326
323
workflow.Select(
327
324
ctx,
328
-
workflow.Await(f1, func (ctx workflow.Context, f Future) {
329
-
var r int
330
-
err := f.Get(ctx, &r)
325
+
workflow.Await(f1, func (ctx workflow.Context, f Future[int]) {
326
+
r, err := f.Get(ctx)
331
327
// ...
332
328
}),
333
-
workflow.Receive(c, func (ctx workflow.Context, c Channel) {
334
-
v, _ := c.Receive(ctx)
335
-
// ...
329
+
workflow.Receive(c, func (ctx workflow.Context, v int, ok bool) {
0 commit comments