{"id":18924641,"url":"https://github.com/dash-os/set-queue","last_synced_at":"2026-03-14T04:30:18.325Z","repository":{"id":57356949,"uuid":"92639701","full_name":"Dash-OS/set-queue","owner":"Dash-OS","description":"Simple FIFO Queue built on top of ES6 Set","archived":false,"fork":false,"pushed_at":"2017-05-31T22:50:20.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-31T17:38:58.976Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dash-OS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-28T04:25:11.000Z","updated_at":"2017-05-28T04:29:26.000Z","dependencies_parsed_at":"2022-09-12T18:41:42.863Z","dependency_job_id":null,"html_url":"https://github.com/Dash-OS/set-queue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dash-OS%2Fset-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dash-OS%2Fset-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dash-OS%2Fset-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dash-OS%2Fset-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dash-OS","download_url":"https://codeload.github.com/Dash-OS/set-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239921875,"owners_count":19718842,"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-11-08T11:07:39.102Z","updated_at":"2026-03-14T04:30:18.254Z","avatar_url":"https://github.com/Dash-OS.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SetQueue \n\nExtremely simple FIFO Queue using ES6 Set. Note that Set's require every value to \nbe unique so this is generally better suited for dealing with situations other than \nsimple values.\n\n\u003e Package Developer uses this to handle queues of Promises where we want to process \n\u003e the resolved promises in a FIFO-fashion on-demand.\n\nAt this time the package only implements the `Set` api partially and it is meant to \njust be a simple queue mechanism.  `Set` was used here over array as it will allow \nus to easily manipulate the queue in the future (for example directly removing values).\n\n### Example\n\n```js\nimport SetQueue from 'set-queue'\n\nconst Queue = new SetQueue()\n\nQueue.add(1).add(2).add(3)\n\nQueue.size ; // 3\n\nconst value = Queue.next() ; // 1\n\nQueue.size ; // 2\n\nfor ( let item of Queue ) {\n  console.log(item) ; // 2, 3\n}\n\nQueue.size ; // 0\n```\n\n### SagaObservable Example\n\nBelow is the source for [saga-observable](https://github.com/Dash-OS/saga-observable) which \nis what the micro-package was developed for.\n\n```js\nimport { cancelled } from 'redux-saga/effects'\nimport { CANCEL } from 'redux-saga'\nimport SetQueue from 'set-queue'\n\nconst CreateSagaPromise = (promise, handler, oncancel) =\u003e {\n  const SagaPromise = new promise(handler)\n  SagaPromise[CANCEL] = oncancel\n  return SagaPromise\n}\n\nconst build_config = config =\u003e ({\n  name: 'saga-observable',\n  promise: Promise,\n  throttle: undefined,\n  ...config\n})\n\nexport default class SagaObservable {\n  constructor(config) {\n    this.config = build_config(config)\n    this.promise = this.config.promise\n    this.name = Symbol(this.config.name)\n    this.queues = {\n      actions:  new SetQueue(),\n      dispatch: new SetQueue(),\n    }\n  }\n\n  publish = (...args) =\u003e {\n    if (this.queues.dispatch.size) {\n      this.queues.dispatch.next()(args)\n    } else {\n      this.queues.actions.add(args)\n    }\n  }\n\n  next = () =\u003e {\n    if (this.queues.actions.length) {\n      return this.promise.resolve(this.queues.actions.next())\n    } else {\n      return CreateSagaPromise(\n        this.promise,\n        resolve =\u003e this.queues.dispatch.add(resolve),\n        this.cancelled\n      )\n    }\n  }\n\n  cancelled = () =\u003e {\n    this.isCancelled = true\n    delete this.queues\n    delete this.promise\n    this.next = () =\u003e { throw new Error(`[SagaObservable] : ${this.name} next called after Cancellation`) }\n    this.publish = (...args) =\u003e { console.warn('[SagaObservable] : Publish Received after Cancellation ', this.name, args) }\n    return cancelled()\n  }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdash-os%2Fset-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdash-os%2Fset-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdash-os%2Fset-queue/lists"}