Documentation
Table of Contents

Method TryCreateStateAsync

Namespace
IntentSharp.Documents
Assembly
IntentSharp.dll

TryCreateStateAsync(string, JsonNode, CancellationToken)

Creates a state value only when the key has none: of several writers, in one process or several, that create the same key at once, exactly one stores its value. Returns the entry as written, with its etag; null when the key already has a value, and then nothing was written. Read the key to see the value that is there.

public ValueTask<StateEntry?> TryCreateStateAsync(string key, JsonNode value, CancellationToken ct = default)

Parameters

key string

The state key.

value JsonNode

The value to store; the store keeps a copy.

ct CancellationToken

Cancels the call.

Returns

ValueTask<StateEntry>

Remarks

The default implementation reads the key with ReadStateAsync(string, CancellationToken) and, when it has no value, writes it with WriteStateAsync(string, JsonNode, string?, CancellationToken) and no expected etag. That is not atomic: two writers that read at once can both create, and the later write replaces the earlier one. A store that several clients or processes share overrides this member with a create that is atomic in its storage; InMemoryDocumentStore and FolderDocumentStore do.

Exceptions

ArgumentException

key is null or blank.

ArgumentNullException

value is null.