Skip to main content

dataStoreRetry

This item is only intended to be used by the module's authors. Private

Provides a utility function to wrap Roblox DataStore API calls with automatic retries for specific, commonly transient error codes.

Purpose: DataStore operations can sometimes fail due to temporary service issues, throttling, or internal errors. This module implements a retry mechanism with exponential backoff to increase the likelihood of success for operations that encounter these transient failures.

Usage:

local DataStoreService = game:GetService("DataStoreService")
local dataStoreRetry = require(script.Parent.dataStoreRetry)
local myStore = DataStoreService:GetDataStore("MyStore")

dataStoreRetry(function()
	-- This function will be retried automatically on specific errors
	return myStore:GetAsync("MyKey")
end):andThen(function(data)
	print("Successfully retrieved data:", data)
end):catch(function(err)
	warn("Failed to get data after retries:", err)
end)

Functions

dataStoreRetry

dataStoreRetry.dataStoreRetry(
func() → T--

The function to execute and potentially retry. This function should perform the desired DataStore operation (e.g., GetAsync, SetAsync, UpdateAsync). It should return the result of the operation on success or throw an error on failure.

) → Promise<T>--

A Promise that resolves with the return value of func if it succeeds within MAX_RETRIES attempts.

Wraps a function that performs a DataStore operation, automatically retrying it if it fails with specific transient error codes.

Implements an exponential backoff strategy: waits 1s, 2s, 4s, 8s between retries.

Errors

TypeDescription
stringRejects with the error message if `func` fails with a non-retriable error code, or if it fails with a retriable error code `MAX_RETRIES` times.
Show raw api
{
    "functions": [
        {
            "name": "dataStoreRetry",
            "desc": "Wraps a function that performs a DataStore operation, automatically retrying it\nif it fails with specific transient error codes.\n\nImplements an exponential backoff strategy: waits 1s, 2s, 4s, 8s between retries.",
            "params": [
                {
                    "name": "func",
                    "desc": "The function to execute and potentially retry. This function should perform the desired DataStore operation (e.g., `GetAsync`, `SetAsync`, `UpdateAsync`). It should return the result of the operation on success or throw an error on failure.",
                    "lua_type": "() -> T"
                }
            ],
            "returns": [
                {
                    "desc": "A Promise that resolves with the return value of `func` if it succeeds within `MAX_RETRIES` attempts.",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "errors": [
                {
                    "lua_type": "string",
                    "desc": "Rejects with the error message if `func` fails with a non-retriable error code, or if it fails with a retriable error code `MAX_RETRIES` times."
                }
            ],
            "source": {
                "line": 74,
                "path": "src/dataStoreRetry.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "dataStoreRetry",
    "desc": "Provides a utility function to wrap Roblox DataStore API calls with automatic\nretries for specific, commonly transient error codes.\n\n**Purpose:** DataStore operations can sometimes fail due to temporary service issues,\nthrottling, or internal errors. This module implements a retry mechanism with\nexponential backoff to increase the likelihood of success for operations that\nencounter these transient failures.\n\n**Usage:**\n```lua\nlocal DataStoreService = game:GetService(\"DataStoreService\")\nlocal dataStoreRetry = require(script.Parent.dataStoreRetry)\nlocal myStore = DataStoreService:GetDataStore(\"MyStore\")\n\ndataStoreRetry(function()\n\t-- This function will be retried automatically on specific errors\n\treturn myStore:GetAsync(\"MyKey\")\nend):andThen(function(data)\n\tprint(\"Successfully retrieved data:\", data)\nend):catch(function(err)\n\twarn(\"Failed to get data after retries:\", err)\nend)\n```",
    "private": true,
    "source": {
        "line": 29,
        "path": "src/dataStoreRetry.luau"
    }
}