Azure / Azure/durabletask

Correct use of external APIs - wrapping to get async behaviour

Open
#139 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1.7k
Forks
335
Avg merge
2d 23h
Merged PRs (30d)
6

Description

From reading the docs I've got the impression that individual activities are recoverable and this is achieved through async/await. So if an activity makes a call to some external API whose behaviour is unpredictable (it may fail or work, it may produce a different return value), then the activity is non-deterministic.

e.g. `var contents = File.ReadAllText("todo.txt")` - the filename parameter is constant, but the file's contents are not, and they may control what happens next.

In cases where no async flavour of the API is available, is the correct approach just to wrap the call to the external API in a Task.Run and then await it?

```cs
var contents = await Task.Run(() => File.ReadAllText("todo.txt"));
```

So that on recovery when that line is replayed, it will return the contents of `todo` as they were originally? And given that this means serialization, the return value of the awaited task must be (JSON) serializable. Is this correct?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.