| IRingbufferTAddAsync Method |
Asynchronously writes an item with a configurable
OverflowPolicy
.
If there is space in the ringbuffer, the call will return the sequence of the written item.
If there is no space, it depends on the overflow policy what happens:
- Overwrite
: we just overwrite the oldest item in the ringbuffer and we violate
the ttl
- Fail
: we return -1
The reason that FAIL exist is to give the opportunity to obey the ttl. If blocking behavior is required,
this can be implemented using retrying in combination with a exponential backoff. Example:
int sleepMs = 100;
for (; ; ) {
long result = ringbuffer.AddAsync(item, OverflowPolicy.Fail).Result;
if (result != -1) {
break;
}
Thread.Sleep(sleepMs);
sleepMs = Math.Min(5000, sleepMs * 2);
}
Namespace:
Hazelcast.Core
Assembly:
Hazelcast.Net (in Hazelcast.Net.dll) Version: 3.12.3
Syntax Task<long> AddAsync(
T item,
OverflowPolicy overflowPolicy
)
Function AddAsync (
item As T,
overflowPolicy As OverflowPolicy
) As Task(Of Long)
Task<long long>^ AddAsync(
T item,
OverflowPolicy overflowPolicy
)
abstract AddAsync :
item : 'T *
overflowPolicy : OverflowPolicy -> Task<int64>
Parameters
- item
- Type: T
the item to add - overflowPolicy
- Type: Hazelcast.CoreOverflowPolicy
the OverflowPolicy to use.
Return Value
Type:
TaskInt64the sequenceId of the added item, or -1 if the add failed.
Exceptions Exception | Condition |
---|
ArgumentNullException | if item or overflowPolicy is null. |
See Also