From 464d3c7088ae9d03574b71459b16c8875f49a336 Mon Sep 17 00:00:00 2001 From: mikeee Date: Thu, 29 Feb 2024 00:10:05 +0000 Subject: [PATCH] add go limitions Signed-off-by: mikeee --- .../workflow/workflow-features-concepts.md | 63 ++++++++++++++++--- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-features-concepts.md b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-features-concepts.md index b39589eda..ddb0371af 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-features-concepts.md +++ b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-features-concepts.md @@ -172,7 +172,7 @@ APIs that generate random numbers, random UUIDs, or the current date are _non-de For example, instead of this: -{{< tabs ".NET" Java JavaScript >}} +{{< tabs ".NET" Java JavaScript Go>}} {{% codetab %}} @@ -207,11 +207,20 @@ const randomString = getRandomString(); {{% /codetab %}} +{{% codetab %}} + +```go +// DON'T DO THIS! +const currentTime = time.Now() +``` + +{{% /codetab %}} + {{< /tabs >}} Do this: -{{< tabs ".NET" Java JavaScript >}} +{{< tabs ".NET" Java JavaScript Go >}} {{% codetab %}} @@ -245,6 +254,14 @@ const randomString = yield context.callActivity(getRandomString); {{% /codetab %}} +{{% codetab %}} + +```go +const currentTime = ctx.CurrentUTCDateTime() +``` + +{{% /codetab %}} + {{< /tabs >}} @@ -255,7 +272,7 @@ Instead, workflows should interact with external state _indirectly_ using workfl For example, instead of this: -{{< tabs ".NET" Java JavaScript >}} +{{< tabs ".NET" Java JavaScript Go >}} {{% codetab %}} @@ -298,11 +315,20 @@ fetch('https://postman-echo.com/get') {{% /codetab %}} +{{% codetab %}} + +```go +// DON'T DO THIS! + +``` + +{{% /codetab %}} + {{< /tabs >}} Do this: -{{< tabs ".NET" Java JavaScript >}} +{{< tabs ".NET" Java JavaScript Go >}} {{% codetab %}} @@ -346,7 +372,7 @@ Failure to follow this rule could result in undefined behavior. Any background p For example, instead of this: -{{< tabs ".NET" Java JavaScript >}} +{{< tabs ".NET" Java JavaScript Go >}} {{% codetab %}} @@ -375,11 +401,24 @@ Don't declare JavaScript workflow as `async`. The Node.js runtime doesn't guaran {{% /codetab %}} +{{% codetab %}} + +```go +// DON'T DO THIS! +go func() { + err := ctx.CallActivity(DoSomething).Await(nil) +}() +err := ctx.CreateTimer(time.Second).Await(nil) +``` + +{{% /codetab %}} + + {{< /tabs >}} Do this: -{{< tabs ".NET" Java JavaScript >}} +{{< tabs ".NET" Java JavaScript Go >}} {{% codetab %}} @@ -407,6 +446,16 @@ Since the Node.js runtime doesn't guarantee that asynchronous functions are dete {{% /codetab %}} +{{% codetab %}} + +```go +// Do this! +task := ctx.CallActivity(DoSomething) +task.Await(nil) +``` + +{{% /codetab %}} + {{< /tabs >}} @@ -440,4 +489,4 @@ To work around these constraints: - [Python](https://github.com/dapr/python-sdk/tree/master/examples/demo_workflow) - [JavaScript example](https://github.com/dapr/js-sdk/tree/main/examples/workflow) - [.NET](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow) - - [Java](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows) \ No newline at end of file + - [Java](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows)