{"id":27947813,"url":"https://github.com/deeplay-io/retry-subscription","last_synced_at":"2025-05-07T14:37:23.165Z","repository":{"id":65489783,"uuid":"391874756","full_name":"deeplay-io/retry-subscription","owner":"deeplay-io","description":"Automatically retry subscriptions with exponential backoff","archived":false,"fork":false,"pushed_at":"2023-01-23T06:12:47.000Z","size":118,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-02T01:38:05.056Z","etag":null,"topics":["abort-controller","async-iterable","backoff","change-feed","changefeed","changes","retry","subscription","watch"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deeplay-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-02T08:44:44.000Z","updated_at":"2023-10-15T01:52:05.000Z","dependencies_parsed_at":"2023-02-12T20:50:13.485Z","dependency_job_id":null,"html_url":"https://github.com/deeplay-io/retry-subscription","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeplay-io%2Fretry-subscription","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeplay-io%2Fretry-subscription/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeplay-io%2Fretry-subscription/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeplay-io%2Fretry-subscription/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deeplay-io","download_url":"https://codeload.github.com/deeplay-io/retry-subscription/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252896775,"owners_count":21821334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abort-controller","async-iterable","backoff","change-feed","changefeed","changes","retry","subscription","watch"],"created_at":"2025-05-07T14:37:22.540Z","updated_at":"2025-05-07T14:37:23.154Z","avatar_url":"https://github.com/deeplay-io.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# retry-subscription [![npm version][npm-image]][npm-url] \u003c!-- omit in toc --\u003e\n\nAutomatically retry subscriptions with exponential backoff.\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Collection subscriptions](#collection-subscriptions)\n  - [IxJS operators](#ixjs-operators)\n\n## Installation\n\n```\nnpm install retry-subscription\n```\n\n## Usage\n\n### Collection subscriptions\n\nCollection subscription is defined as a function returning an Async Iterable,\nwhose first emission represent initial collection state, and subsequent\nemissions represent live changes:\n\n```ts\ntype CollectionSubscription = (\n  signal: AbortSignal,\n) =\u003e AsyncIterable\u003cArray\u003cCollectionSubscriptionUpdate\u003cKey, Value\u003e\u003e\u003e;\n\ntype CollectionSubscriptionUpdate\u003cKey extends string | number, Value\u003e = {\n  /**\n   * Unique key of the item in the collection.\n   */\n  key: Key;\n  /**\n   * `undefined` if the item was removed from the collection.\n   */\n  value?: Value | undefined;\n};\n```\n\nTo add retries to a collection subscription, wrap it with\n`retryCollectionSubscription`:\n\n```ts\nfunction retryCollectionSubscription\u003cKey extends string | number, Value\u003e(\n  subscribe: (\n    signal: AbortSignal,\n  ) =\u003e AsyncIterable\u003cArray\u003cCollectionSubscriptionUpdate\u003cKey, Value\u003e\u003e\u003e,\n  options?: RetryCollectionSubscriptionOptions\u003cValue\u003e,\n): AsyncIterable\u003cArray\u003cCollectionSubscriptionUpdate\u003cKey, Value\u003e\u003e\u003e;\n```\n\nWhen an error happens, `retryCollectionSubscription` schedules a retry after\nexponential backoff that grows with each attempt. Upon initial emission after\nretry, attempt number is reset, the previous collection state is compared\nagainst the received initial state, and the resulting Async Iterable only emits\nthe changes that happened during retry attempts.\n\nSupported options:\n\n```ts\ntype RetryCollectionSubscriptionOptions\u003cValue, Revision = Value\u003e = {\n  /**\n   * Signal that can be used to abort retry backoff delays. It is also passed to\n   * the inner subscription.\n   */\n  signal?: AbortSignal;\n  /**\n   * Starting delay before first retry attempt in milliseconds.\n   *\n   * Defaults to 1000.\n   *\n   * Example: if `baseMs` is 100, then retries will be attempted in 100ms,\n   * 200ms, 400ms etc (not counting jitter).\n   */\n  baseMs?: number;\n  /**\n   * Maximum delay between attempts in milliseconds.\n   *\n   * Defaults to 15 seconds.\n   *\n   * Example: if `baseMs` is 1000 and `maxDelayMs` is 3000, then retries will be\n   * attempted in 1000ms, 2000ms, 3000ms, 3000ms etc (not counting jitter).\n   */\n  maxDelayMs?: number;\n  /**\n   * Maximum for the total number of attempts.\n   *\n   * Defaults to `Infinity`.\n   */\n  maxAttempts?: number;\n  /**\n   * Called when an error is thrown by inner subscription, before setting delay\n   * timer.\n   *\n   * If at the time of error the inner subscription was initialized (i.e. has\n   * had initial emission), then the `attempt` and `delayMs` will be\n   * `undefined`, and the retry will happen immediately.\n   *\n   * If the error happened before initialization, then the `attempt` will start\n   * from 0 and will be incremented with each attempt, and the retry will happen\n   * after exponential backoff.\n   *\n   * Rethrow error from this callback to prevent further retries.\n   */\n  onError?: (\n    error: unknown,\n    attempt: number | undefined,\n    delayMs: number | undefined,\n  ) =\u003e void;\n  /**\n   * If the value has a field that is changed each time the collection item\n   * changes, consider returning supplying `getRevision` function that returns\n   * it. This way, less memory will be needed to store the state, and less CPU\n   * will be needed for diffing algorithm on resubscription.\n   *\n   * Defaults to identity function, i.e. the revision is the whole value.\n   */\n  getRevision?: (value: Value) =\u003e Revision;\n  /**\n   * Equality function used by diffing algorithm on resubscription.\n   *\n   * Defaults to deep equality.\n   */\n  equality?: (a: Revision, b: Revision) =\u003e boolean;\n};\n```\n\n### IxJS operators\n\nAll functions are also exported in form of\n[`IxJS`](https://github.com/ReactiveX/IxJS) operators from\n`retry-subscription/ix` module.\n\n[npm-image]: https://badge.fury.io/js/retry-subscription.svg\n[npm-url]: https://badge.fury.io/js/retry-subscription\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeeplay-io%2Fretry-subscription","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeeplay-io%2Fretry-subscription","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeeplay-io%2Fretry-subscription/lists"}