mirror of
https://github.com/ZeroCatDev/Classworks.git
synced 2026-02-04 07:53:11 +00:00
Add JSDoc clarification for callback snapshot behavior
Co-authored-by: Sunwuyuan <88357633+Sunwuyuan@users.noreply.github.com>
This commit is contained in:
parent
b084c80b18
commit
a997e35162
@ -32,6 +32,7 @@ export function getServerList(provider) {
|
|||||||
* @param {Object} options - Options
|
* @param {Object} options - Options
|
||||||
* @param {string} options.provider - Provider type (optional, defaults to current setting)
|
* @param {string} options.provider - Provider type (optional, defaults to current setting)
|
||||||
* @param {Function} options.onServerTried - Callback called when a server is tried (optional)
|
* @param {Function} options.onServerTried - Callback called when a server is tried (optional)
|
||||||
|
* Receives: { url, status, tried } where tried is a snapshot of attempts
|
||||||
* @returns {Promise} Result from the first successful server, or throws the last error
|
* @returns {Promise} Result from the first successful server, or throws the last error
|
||||||
*/
|
*/
|
||||||
export async function tryWithRotation(operation, options = {}) {
|
export async function tryWithRotation(operation, options = {}) {
|
||||||
@ -47,6 +48,7 @@ export async function tryWithRotation(operation, options = {}) {
|
|||||||
try {
|
try {
|
||||||
triedServers.push({ url: serverUrl, status: "trying" });
|
triedServers.push({ url: serverUrl, status: "trying" });
|
||||||
if (hasCallback) {
|
if (hasCallback) {
|
||||||
|
// Provide a snapshot to prevent callback from mutating internal state
|
||||||
onServerTried({ url: serverUrl, status: "trying", tried: [...triedServers] });
|
onServerTried({ url: serverUrl, status: "trying", tried: [...triedServers] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user