UNPKG

@magiceden/magiceden-sdk

Version:

A TypeScript SDK for interacting with Magic Eden's API across multiple chains.

69 lines (68 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RetryablePromise = void 0; const retry_1 = require("./retry"); /** * A Promise wrapper that allows for optional retry behavior */ class RetryablePromise { /** * Creates a new RetryablePromise * * @param operation The async operation to potentially retry */ constructor(operation) { this.retryEnabled = false; this.operation = operation; } getPromise() { if (this.retryEnabled) { return (0, retry_1.retryOperation)(this.operation, this.retryOptions); } else { return this.operation(); } } /** * Enables retry behavior with optional configuration * * @param options Optional retry configuration * @returns This RetryablePromise instance for chaining */ withRetries(options) { this.retryEnabled = true; this.retryOptions = options; return this; } /** * Implementation of PromiseLike interface */ then(onfulfilled, onrejected) { return this.getPromise().then(onfulfilled, onrejected); } /** * Adds a catch handler to the promise */ catch(onrejected) { return this.getPromise().catch(onrejected); } /** * Adds a finally handler to the promise */ finally(onfinally) { return this.getPromise().finally(onfinally); } /** * Converts to a standard Promise */ toPromise() { return this.getPromise(); } /** * Creates a RetryablePromise from an operation */ static from(operation) { return new RetryablePromise(operation); } } exports.RetryablePromise = RetryablePromise;