hashMapRetry
Provides a utility function to wrap Roblox MemoryStoreService HashMap API calls
(like GetAsync, SetAsync, UpdateAsync) with automatic retries for specific,
commonly transient error conditions identified by error message strings.
Purpose: Similar to dataStoreRetry, MemoryStore operations can fail due to temporary service issues, throttling, or internal errors. This module implements a retry mechanism with exponential backoff to handle these transient failures. It differs from dataStoreRetry by matching against error strings rather than numeric codes, as MemoryStore errors often manifest this way. It also includes a cancellation mechanism.
Usage:
local MemoryStoreService = game:GetService("MemoryStoreService")
local hashMapRetry = require(script.Parent.hashMapRetry)
local myMap = MemoryStoreService:GetHashMap("MyMap")
local handle = hashMapRetry(function()
-- This function will be retried automatically on specific errors
return myMap:GetAsync("MyKey")
end)
handle.promise:andThen(function(data)
print("Successfully retrieved data:", data)
end):catch(function(err)
warn("Failed to get data after retries or cancelled:", err)
end)
-- To cancel the operation:
-- handle.cancel()
Functions
hashMapRetry
hashMapRetry.hashMapRetry(func: () → any--
The function to execute and potentially retry. This function should perform the desired MemoryStore HashMap operation (e.g., GetAsync, SetAsync, UpdateAsync). It should return the result on success or throw an error on failure.
) → RetryHandle<Promise<any>>--
A handle containing: promise (A Promise that resolves with the return value of func if it succeeds within MAX_RETRIES attempts) and cancel (A function that, when called, attempts to stop further retries and rejects the promise).
Wraps a function that performs a MemoryStore HashMap operation, automatically retrying it if it fails with specific transient error message substrings.
Implements an exponential backoff strategy: waits 1s, 2s, 4s, 8s between retries. Includes a cancellation mechanism via the returned [RetryHandle].
Errors
| Type | Description |
|---|---|
| string | Rejects if `func` fails with a non-retriable error, if it fails with a retriable error `MAX_RETRIES` times, or if `cancel()` is called. |