IReliableDictionary<TKey,TValue>.GetOrAddAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
GetOrAddAsync(ITransaction, TKey, TValue, TimeSpan, CancellationToken) |
Adds a key/value pair to the Reliable Dictionary if the key does not already exist. |
GetOrAddAsync(ITransaction, TKey, Func<TKey,TValue>, TimeSpan, CancellationToken) |
Adds a key/value pair to the Reliable Dictionary by using the specified function, if the key does not already exist. |
GetOrAddAsync(ITransaction, TKey, Func<TKey,TValue>) |
Adds a key/value pair to the Reliable Dictionary by using the specified function, if the key does not already exist. |
GetOrAddAsync(ITransaction, TKey, TValue) |
Adds a key/value pair to the Reliable Dictionary if the key does not already exist. If the key exists no updates will be made to the value. |
GetOrAddAsync(ITransaction, TKey, TValue, TimeSpan, CancellationToken)
Adds a key/value pair to the Reliable Dictionary if the key does not already exist.
public System.Threading.Tasks.Task<TValue> GetOrAddAsync (Microsoft.ServiceFabric.Data.ITransaction tx, TKey key, TValue value, TimeSpan timeout, System.Threading.CancellationToken cancellationToken);
abstract member GetOrAddAsync : Microsoft.ServiceFabric.Data.ITransaction * 'Key * 'Value * TimeSpan * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Value>
Public Function GetOrAddAsync (tx As ITransaction, key As TKey, value As TValue, timeout As TimeSpan, cancellationToken As CancellationToken) As Task(Of TValue)
Parameters
- tx
- ITransaction
Transaction to associate this operation with.
- key
- TKey
The key of the element to add.
- value
- TValue
The value to be added, if the key does not already exist.
- timeout
- TimeSpan
The amount of time to wait for the operation to complete before throwing a TimeoutException. Primarily used to prevent deadlocks. The default is 4 seconds.
- cancellationToken
- CancellationToken
The token to monitor for cancellation requests. The default is None.
Returns
A task that represents the asynchronous add operation. The task result is the value for the key. This will be either the existing value for the key if the key is already in the Reliable Dictionary, or the new value if the key was not in the Reliable Dictionary.
Exceptions
tx
is null, or key
is null or cannot be serialized.
timeout
is negative.
The operation failed to complete within the given timeout.
The operation was canceled.
The exception that is thrown when the IReliableDictionary<TKey,TValue> is not in Primary.
The transaction has been internally faulted by the system. Retry the operation on a new transaction
Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.
Indicates that the Reliable Dictionary is closed or deleted.
Applies to
GetOrAddAsync(ITransaction, TKey, Func<TKey,TValue>, TimeSpan, CancellationToken)
Adds a key/value pair to the Reliable Dictionary by using the specified function, if the key does not already exist.
public System.Threading.Tasks.Task<TValue> GetOrAddAsync (Microsoft.ServiceFabric.Data.ITransaction tx, TKey key, Func<TKey,TValue> valueFactory, TimeSpan timeout, System.Threading.CancellationToken cancellationToken);
abstract member GetOrAddAsync : Microsoft.ServiceFabric.Data.ITransaction * 'Key * Func<'Key, 'Value (requires 'Key :> IComparable<'Key> and 'Key :> IEquatable<'Key>)> * TimeSpan * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Value>
Public Function GetOrAddAsync (tx As ITransaction, key As TKey, valueFactory As Func(Of TKey, TValue), timeout As TimeSpan, cancellationToken As CancellationToken) As Task(Of TValue)
Parameters
- tx
- ITransaction
Transaction to associate this operation with.
- key
- TKey
The key of the element to add.
- valueFactory
- Func<TKey,TValue>
The function used to generate a value for the key.
- timeout
- TimeSpan
The amount of time to wait for the operation to complete before throwing a TimeoutException. Primarily used to prevent deadlocks. The default is 4 seconds.
- cancellationToken
- CancellationToken
The token to monitor for cancellation requests. The default is None.
Returns
A task that represents the asynchronous add operation. The task result is the value for the key. This will be either the existing value for the key if the key is already in the Reliable Dictionary, or the new value for the key as returned by valueFactory if the key was not in the Reliable Dictionary.
Exceptions
tx
is null, or key
is null or cannot be serialized, or valueFactory
is null.
timeout
is negative.
The operation failed to complete within the given timeout.
The operation was canceled.
The exception that is thrown when the IReliableDictionary<TKey,TValue> is not in Primary.
The transaction has been internally faulted by the system. Retry the operation on a new transaction
Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.
Indicates that the Reliable Dictionary is closed or deleted.
Applies to
GetOrAddAsync(ITransaction, TKey, Func<TKey,TValue>)
Adds a key/value pair to the Reliable Dictionary by using the specified function, if the key does not already exist.
public System.Threading.Tasks.Task<TValue> GetOrAddAsync (Microsoft.ServiceFabric.Data.ITransaction tx, TKey key, Func<TKey,TValue> valueFactory);
abstract member GetOrAddAsync : Microsoft.ServiceFabric.Data.ITransaction * 'Key * Func<'Key, 'Value (requires 'Key :> IComparable<'Key> and 'Key :> IEquatable<'Key>)> -> System.Threading.Tasks.Task<'Value>
Public Function GetOrAddAsync (tx As ITransaction, key As TKey, valueFactory As Func(Of TKey, TValue)) As Task(Of TValue)
Parameters
- tx
- ITransaction
Transaction to associate this operation with.
- key
- TKey
The key of the element to add.
- valueFactory
- Func<TKey,TValue>
The function used to generate a value for the key.
Returns
A task that represents the asynchronous add operation. The task result is the value for the key. This will be either the existing value for the key if the key is already in the Reliable Dictionary, or the new value for the key as returned by valueFactory if the key was not in the Reliable Dictionary.
Exceptions
tx
is null, or key
is null or cannot be serialized, or valueFactory
is null.
The operation failed to complete within the default timeout.
The exception that is thrown when the IReliableDictionary<TKey,TValue> is not in Primary.
The transaction has been internally faulted by the system. Retry the operation on a new transaction
Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.
Indicates that the Reliable Dictionary is closed or deleted.
Applies to
GetOrAddAsync(ITransaction, TKey, TValue)
Adds a key/value pair to the Reliable Dictionary if the key does not already exist. If the key exists no updates will be made to the value.
public System.Threading.Tasks.Task<TValue> GetOrAddAsync (Microsoft.ServiceFabric.Data.ITransaction tx, TKey key, TValue value);
abstract member GetOrAddAsync : Microsoft.ServiceFabric.Data.ITransaction * 'Key * 'Value -> System.Threading.Tasks.Task<'Value>
Public Function GetOrAddAsync (tx As ITransaction, key As TKey, value As TValue) As Task(Of TValue)
Parameters
- tx
- ITransaction
Transaction to associate this operation with.
- key
- TKey
The key of the element to add.
- value
- TValue
The value to be added, if the key does not already exist.
Returns
A task that represents the asynchronous add operation. The task result is the value for the key. This will be either the existing value for the key if the key is already in the Reliable Dictionary, or the new value if the key was not in the Reliable Dictionary.
Exceptions
tx
is null, or key
is null or cannot be serialized.
The operation failed to complete within the default timeout.
The exception that is thrown when the IReliableDictionary<TKey,TValue> is not in Primary.
The transaction has been internally faulted by the system. Retry the operation on a new transaction
Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.
Indicates that the Reliable Dictionary is closed or deleted.
Applies to
Azure SDK for .NET