{"id":21522216,"url":"https://github.com/greguz/rxlax","last_synced_at":"2025-03-17T17:23:18.391Z","repository":{"id":33950823,"uuid":"163870614","full_name":"greguz/rxlax","owner":"greguz","description":"Make Rx.js to relax a bit","archived":false,"fork":false,"pushed_at":"2022-12-30T19:02:25.000Z","size":337,"stargazers_count":0,"open_issues_count":9,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-24T15:09:55.929Z","etag":null,"topics":["backpressure","rxjs","stream"],"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/greguz.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":"2019-01-02T17:39:19.000Z","updated_at":"2019-11-08T09:26:01.000Z","dependencies_parsed_at":"2023-01-15T03:33:33.432Z","dependency_job_id":null,"html_url":"https://github.com/greguz/rxlax","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Frxlax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Frxlax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Frxlax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Frxlax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greguz","download_url":"https://codeload.github.com/greguz/rxlax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244075655,"owners_count":20393980,"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":["backpressure","rxjs","stream"],"created_at":"2024-11-24T01:09:37.532Z","updated_at":"2025-03-17T17:23:18.245Z","avatar_url":"https://github.com/greguz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rxlax\n\n[![npm version](https://badge.fury.io/js/rxlax.svg)](https://badge.fury.io/js/rxlax) [![Build Status](https://travis-ci.com/greguz/rxlax.svg?branch=master)](https://travis-ci.com/greguz/rxlax) [![Coverage Status](https://coveralls.io/repos/github/greguz/rxlax/badge.svg?branch=master)](https://coveralls.io/github/greguz/rxlax?branch=master) [![Dependencies Status](https://david-dm.org/greguz/rxlax.svg)](https://david-dm.org/greguz/rxlax.svg)\n\nMake Rx.js to relax a bit.\n\nThis lib is useful to handle the [backpressure](https://nodejs.org/en/docs/guides/backpressuring-in-streams/) problem with Rx.js.\nCurrently there are _other methods_ to handle this problem,\nbut I've found that these methods are not always suitable for all cases,\nor the resulting code is just too complicated to achieve a simple solution.\nThis lib try to solve this problematic with just a single operator.\n\n- Node.js \u0026 Browser support\n- Rx.js 6.x\n- Zero dependencies\n- TypeScript support\n\nTechnically this operator map the source data to observable of resulting data, so you have to use another operator like [mergeAll](https://rxjs-dev.firebaseapp.com/api/operators/mergeAll) to retrieve the resulting data, or in other words convert a higher-order Observable into a first-order Observable.\n\n## Example\n\n```javascript\nconst { mergeAll, toArray } = require(\"rxjs/operators\");\nconst { rxlax } = require(\"rxlax\");\n\nfunction getBigAndFastFiringObservable() {\n  // Return a fast-firing observable, like an array or a file read\n}\n\nasync function slowAsyncProcess(data) {\n  await doSomethingCool(data);\n  return {\n    ts: new Date(),\n    id: data.id\n  };\n}\n\nconst results = await getBigAndFastFiringObservable()\n  .pipe(rxlax(slowAsyncProcess, { concurrency: 10 }))\n  .pipe(mergeAll())\n  .pipe(toArray())\n  .toPromise();\n```\n\n## Mapper\n\nThe first argument is a map function,\nthat takes a stream element as argument and returns an [observable input](https://rxjs-dev.firebaseapp.com/api/index/type-alias/ObservableInput).\nThis is the **async** process that have to be limited according to the\nspeed of the data source.\n\n## Options\n\nThe second argument are the options.\n\n```typescript\ninterface Options\u003cT\u003e {\n  concurrency?: number;\n  queue?: () =\u003e Queue\u003cT\u003e;\n}\n```\n\n### Concurrency\n\nNumber of concurrent jobs, default to [16](https://nodejs.org/api/stream.html#stream_constructor_new_stream_writable_options).\n\n### Custom queue\n\nBy default, all queued data is saved in memory,\ntecnically a simple array,\nbut if the data to precess is enormous,\nor the processing time is very long,\nit is recommend to use a custom queue to buffer the data.\n\n```typescript\ninterface Queue\u003cT\u003e {\n  shift: () =\u003e Promise\u003cT | undefined\u003e;\n  push: (entry: T) =\u003e Promise\u003cany\u003e;\n  clear: () =\u003e Promise\u003cany\u003e;\n}\n```\n\nA custom queue have to implement 3 methods used internally by **rxlax**,\nall of them are **async**, so you can use any DB as queue storage.\n\n#### push(entry: T): Promise\u003cany\u003e\n\nAdd one element to the end of the queue.\n\n#### shift(): Promise\u003cT | undefined\u003e\n\nRemoves the first element from the queue and returns that removed element.\n\n#### clear(): Promise\u003cany\u003e\n\nClear the queue. This method is always fired just before the end of the overall process.\n\n### Returns all errors\n\nIf the option **multiError** is true, and more than one error are collected,\nthe resulting error will be a custom instance whit an _errors_ property.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreguz%2Frxlax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreguz%2Frxlax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreguz%2Frxlax/lists"}