{"id":16822515,"url":"https://github.com/strml/subscription-dedupe","last_synced_at":"2025-06-11T05:06:55.451Z","repository":{"id":43002466,"uuid":"105494338","full_name":"STRML/subscription-dedupe","owner":"STRML","description":"Simple module for reference-counting topic subscriptions","archived":false,"fork":false,"pushed_at":"2022-03-24T01:49:32.000Z","size":224,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-10T15:15:34.741Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/STRML.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-02T03:23:30.000Z","updated_at":"2021-03-31T21:47:30.000Z","dependencies_parsed_at":"2022-09-02T17:21:59.883Z","dependency_job_id":null,"html_url":"https://github.com/STRML/subscription-dedupe","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Fsubscription-dedupe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Fsubscription-dedupe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Fsubscription-dedupe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Fsubscription-dedupe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/STRML","download_url":"https://codeload.github.com/STRML/subscription-dedupe/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Fsubscription-dedupe/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259204809,"owners_count":22821160,"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":[],"created_at":"2024-10-13T11:04:33.389Z","updated_at":"2025-06-11T05:06:55.427Z","avatar_url":"https://github.com/STRML.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Subscription-Dedupe\n\nA simple module for reference-counting subscriptions and delegating to a handler.\n\n### Usage\n\nThis simple example shows how to dedupe subscriptions to Redis.\n\nWhen creating a `SubscriptionDedupe`, you must define two methods, `onSubscribe` and `onUnsubscribe`.\nIf you wish to listen to success/error, you should return a Promise.\n\n```js\nconst SubscriptionDedupe = require(\"subscription-dedupe\");\nconst redis = require('redis');\nconst Promise = require('bluebird');\n\nconst redisClient = redis.createClient({/*...*/});\nconst psubscribeAsync = Promise.promisify(redisClient.psubscribe, {context: redisClient});\nconst punsubscribeAsync = Promise.promisify(redisClient.punsubscribe, {context: redisClient});\nconst deduper = new SubscriptionDedupe({\n  onSubscribe(topic) {\n    return psubscribeAsync(topic);\n  },\n  onUnsubscribe(topic) {\n    return punsubscribeAsync(topic);\n  },\n  // If `false`, will not print to console.warn if your code unsubscribes more\n  // than it subscribes (which would result in a negative refCount).\n  // Default `true`\n  warnOnTooManyUnsubscribes: true,\n});\n\n//\n// Usage\n//\n\n// onSubscribe() called\nawait deduper.subscribe('topic');\n// onSubscribe() NOT called! The original, resolved promise is returned instead.\nawait deduper.subscribe('topic');\n\n// onUnsubscribe NOT called, as there is still an open subscription.\nawait deduper.unsubscribe('topic');\n// onUnsubscribe() called\nawait deduper.unsubscribe('topic');\n\n//\n// Recovering from errors\n//\n\ntry {\n  await deduper.subscribe('topic');\n} catch (e) {\n  // handle error...\n\n  // Be sure to unsubscribe - or this will count as a subscription and new attempts will also throw!\n  // This module doesn't check if the promise threw.\n  await deduper.unsubscribe('topic');\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrml%2Fsubscription-dedupe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrml%2Fsubscription-dedupe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrml%2Fsubscription-dedupe/lists"}