{"name":"@repeaterjs/repeater","version":"3.0.0-beta.1","description":"The missing constructor function for creating safe async iterators","repository":{"type":"git","url":"https://github.com/repeaterjs/repeater","directory":"packages/repeater"},"license":"MIT","main":"lib/repeater.cjs.js","module":"lib/repeater.esm.js","types":"lib/repeater.d.ts","scripts":{"prebuild":"yarn run clean","build":"rollup -c ./rollup.config.js","clean":"shx rm -rf ./lib","lint":"eslint --ext ts src","prepublishOnly":"yarn run test && yarn run build","test":"jest --config ./jest.config.js --rootDir --color"},"devDependencies":{"@types/jest":"^24.0.18","@typescript-eslint/eslint-plugin":"^2.3.3","@typescript-eslint/parser":"^2.3.3","eslint":"^6.5.1","eslint-config-prettier":"^6.4.0","eslint-config-recommended-plus-types":"^1.0.0","eslint-plugin-jest":"^22.19.0","eslint-plugin-prettier":"^3.1.1","jest":"^24.9.0","prettier":"^1.18.2","rollup":"^1.23.1","rollup-plugin-typescript2":"^0.24.3","shx":"^0.3.2","ts-jest":"^24.1.0","typescript":"^3.6.4","weak":"^1.0.1"},"publishConfig":{"access":"public"},"readmeFilename":"README.md","readme":"# @repeaterjs/repeater\nThe missing constructor for creating safe async iterators\n\nFor more information, visit [repeater.js.org](https://repeater.js.org).\n\n## API\n\n```ts\nclass Repeater<T> implements AsyncIterableIterator<T> {\n  constructor(executor: RepeaterExecutor<T>, buffer?: RepeaterBuffer<T>);\n  next(value?: any): Promise<IteratorResult<T>>;\n  return(value?: any): Promise<IteratorResult<T>>;\n  throw(error: any): Promise<IteratorResult<T>>;\n  [Symbol.asyncIterator](): this;\n}\n```\n\nThe `Repeater` class implements the `AsyncIterableIterator` interface. Repeaters are designed to be indistinguishable from async generator objects.\n\n```ts\ntype Push<T> = (value: PromiseLike<T> | T) => Promise<any | void>;\n\ninterface Stop extends Promise<any | void> {\n  (error?: any): void;\n}\n\ntype RepeaterExecutor<T> = (\n  push: Push<T>,\n  stop: Stop\n) => Promise<T | void> | T | void;\n```\n\nThe `RepeaterExecutor` is passed the arguments `push` and `stop`.\n\n`push` is a function which allows you to enqueue values onto the repeater. It synchronously throws an error if there are too many pending pushes on the repeater (currently set to 1024). It returns a promise which resolves when it’s safe to push more values.\n\n`stop` is a both a promise and a function. As a function, `stop` can be called to stop a repeater. Calling `stop` without any arguments stops the repeater without error, and passing an error both stops the repeater and causes the final iteration to reject with that error.\n\nAs a promise, `stop` can be awaited to defer event handler cleanup, and it can also be used with `Promise.race` to abort pending promises. If you pass a value to `Repeater.prototype.return`, `stop` will resolve to that value.\n\nThe value of the final interation of the repeater will be the return value of the executor. If the executor throws an error or returns a promise rejection, the repeater will be immediately stopped and the final iteration will throw.\n\n```ts\ninterface RepeaterBuffer<T> {\n  full: boolean;\n  empty: boolean;\n  add(value: T): void;\n  remove(): T | undefined;\n}\n\nclass FixedBuffer<T> implements RepeaterBuffer<T> {\n  constructor(capacity: number);\n}\n\nclass SlidingBuffer<T> implements RepeaterBuffer<T> {\n  constructor(capacity: number);\n}\n\nclass DroppingBuffer<T> implements RepeaterBuffer<T> {\n  constructor(capacity: number);\n}\n```\n\nThe `Repeater` constructor optionally takes a `RepeaterBuffer` instance as its second argument. Buffers allow multiple values to be pushed onto repeaters without waiting. `FixedBuffer` allows repeaters to push a set number of values, `DroppingBuffer` drops the *latest* values when the buffer has reached capacity, and `SlidingBuffer` drops the *earliest* values when the buffer has reached capacity. You can define custom buffering behaviors by implementing the `RepeaterBuffer` interface.\n","_id":"@repeaterjs/repeater@3.0.0-beta.1","dist":{"shasum":"ccb3fbde8a7d0393094db861481d1c4bc7f6cbd1","integrity":"sha512-AhBKnBStxIbe9MjnSwJn3RjOmFvvvNBLeSZliDqo5QJ6l4oKAglLUMOqMaA+IuNGd6USec2LhIIFsr+QlwMJBA==","tarball":"http://registry-npm.ywwl.com/@repeaterjs/repeater/download/@repeaterjs/repeater-3.0.0-beta.1.tgz","fileCount":10,"unpackedSize":53849,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdtlrDCRA9TVsSAnZWagAAo2wP/142q7eyTGGvEfe8EY2g\nZG/+4KEeYq1Lmr0/mVifW40JbXM2zyCFshQIV2KuKmT0NB95GWjlg1v0S0lF\nGA0+vMDdVoTRTzwC1jGSty0WGQn/rT3Ylkj2oyQx9fDpzavjM5ZHwBPdpWzV\nio/+Lg6zv4NiLG+N54BT1W0P5fV++vKSgdWwVjyOPi8+dzCyKw9CS4hIvqjW\nTxJL1nE6qlnZBIrneLeBRFmdWeOjskZgxYEl7Fomtd03ZUWhbZlvw3wk5alp\ndoVVb32TMWpbZZ0Ka5NW29x7Ud3G2PNE4B/j2aNVRTciZlls4prIKsIsZf3+\n8CJbDkRpqoY2VB7sWNHrdXz6i3QHhLK0ZWXSrq9HR1dlvOMorPBNqeU7kfXw\nXu6B73dk8/C+UZb7JgVSeslrPjCQ6F5Bu61VH0ghFnYgngtl7bOr5MV3X9AW\ndt7FzZIChbCWgLeZVwWLM/+xWHUxc1ZiDpfFR5zld5y4JEkwsTG/xr4qyflu\nfch4HaTdqEppgB9d29gkmLQk2fOh9xNOVFogsttvHN/aEyaaD+2HXFcFh4NX\nQi8Offo9n6TuLbT/59os65K6nvWUs6RYANb7J+NBKzo8lO08CCB8RnIZKfhK\ne3Xr5qb+lja86cTc30lnR5joIolwqzjLsuAFYrVT6TA5rDajuKqrqrTfgTkV\n3kqG\r\n=1trN\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGhvzVsIexxsVP2tHU2gKxmgDx+JWUzl9U5ThqUkk4PeAiAj9FzmdMFvUcUvD2dhCy0m7WoUOOgse3ECnSMuDWLUTw=="}],"size":6777,"noattachment":false,"key":"/@repeaterjs/repeater/-/@repeaterjs/repeater-3.0.0-beta.1.tgz"},"maintainers":[{"name":"brainkim","email":"briankimpossible@gmail.com"}],"_npmUser":{"name":"brainkim","email":"briankimpossible@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/repeater_3.0.0-beta.1_1572231875112_0.9366097122430375"},"_hasShrinkwrap":false,"publish_time":1572231875235,"_cnpm_publish_time":1572231875235,"dist-tags":{"beta":"3.1.0-beta.1","latest":"3.1.0"}}