RemoveAsync
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts.
For thread safety, this property is not safe to read in an unsynchronized thread.
Removes an item or items previously read from the queue. This method uses the identifier returned by MemoryStoreQueue/ReadAsync
to identify the items to remove. If called after the invisibility timeout has expired, the call has no effect.
Parameters
Name | Type | Default | Description |
---|---|---|---|
|
Identifies the items to delete. Use the value returned by |
Returns
Return Type | Summary |
---|---|
No returns. |
Code Samples
Using a MemoryStoreQueue
The following code sample demonstrates using MemoryStoreQueue/ReadAsync
and MemoryStoreQueue/RemoveAsync
to reliably read, process, and remove items from a queue. While the processing code can be as complicated as necessary, in this example we simply set a flag in the corresponding datastore item; it guarantees that every item will eventually be processed even if some of the calls encounter errors or the game server crashes:
- If ReadAsync() fails, no items are retrieved from the queue. An item will be picked up for processing during the next iteration of the loop.
- If ReadAsync() succeeds but
DataStoreService/UpdateAsync|ds:UpdateAsync
fails, the item will stay invisible until the queue’s invisibility timeout expires, leading to the item becoming visible again to be returned in a future loop iteration. - Similarly, if RemoveAsync() fails, the item will become visible again in the future and will be processed again.
Note that depending on where the failure happens, it is possible that an item will be processed more than once and the processing code should account for that. It’s not a problem in this sample code since the end result is the same, even if ds:UpdateAsync is invoked multiple times.