Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
d7c1bd06f2 | |||
124400df69 | |||
84d3a6310d | |||
984f7e7bb6 | |||
f4e548aa2c | |||
3f85e9fa3c |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@push.rocks/smartrx",
|
||||
"version": "3.0.5",
|
||||
"version": "3.0.8",
|
||||
"private": false,
|
||||
"description": "smart wrapper for rxjs",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -18,8 +18,8 @@
|
||||
"@gitzone/tsbundle": "^2.0.8",
|
||||
"@gitzone/tsrun": "^1.2.44",
|
||||
"@gitzone/tstest": "^1.0.77",
|
||||
"@push.rocks/tapbundle": "^5.0.12",
|
||||
"@types/node": "^20.4.4"
|
||||
"@push.rocks/tapbundle": "^5.0.15",
|
||||
"@types/node": "^20.8.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"@push.rocks/smartpromise": "^4.0.2",
|
||||
|
1490
pnpm-lock.yaml
generated
1490
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartrx',
|
||||
version: '3.0.5',
|
||||
version: '3.0.8',
|
||||
description: 'smart wrapper for rxjs'
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import * as plugins from './smartrx.plugins.js';
|
||||
export * from './smartrx.classes.observablemap.js';
|
||||
export * from './smartrx.classes.observableintake.js';
|
||||
export * from './smartrx.functions.js';
|
||||
import * as rxjs from './smartrx.plugins.rxjs.js';
|
||||
export { rxjs };
|
||||
|
32
ts/smartrx.functions.ts
Normal file
32
ts/smartrx.functions.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { Observable } from 'rxjs';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
export function fromStreamWithBackpressure<T>(stream: Readable): Observable<T> {
|
||||
return new Observable<T>((subscriber) => {
|
||||
const pauseStream = () => stream.pause();
|
||||
const resumeStream = () => process.nextTick(() => stream.resume());
|
||||
|
||||
// Handler for each piece of data
|
||||
const onData = (data: T) => {
|
||||
// Pause the stream to apply backpressure
|
||||
pauseStream();
|
||||
// Emit data and resume the stream if the subscriber is ready
|
||||
subscriber.next(data);
|
||||
resumeStream();
|
||||
};
|
||||
|
||||
// Subscribe to stream events
|
||||
stream.on('data', onData);
|
||||
stream.on('error', (error) => subscriber.error(error));
|
||||
stream.on('end', () => subscriber.complete());
|
||||
stream.on('close', () => subscriber.complete());
|
||||
|
||||
// If the subscriber unsubscribes, clean up the stream listeners
|
||||
return () => {
|
||||
stream.removeListener('data', onData);
|
||||
stream.removeListener('error', subscriber.error);
|
||||
stream.removeListener('end', subscriber.complete);
|
||||
stream.removeListener('close', subscriber.complete);
|
||||
};
|
||||
});
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
// this file is intended to keep the bundle size down
|
||||
|
||||
export { Observable, Subject, fromEvent, ReplaySubject, Subscription, from } from 'rxjs';
|
||||
export { Observable, Subject, fromEvent, ReplaySubject, Subscription, from, of } from 'rxjs';
|
||||
|
||||
export type { Observer } from 'rxjs';
|
||||
|
||||
import { startWith, takeUntil, map, debounce, debounceTime, throttleTime } from 'rxjs/operators';
|
||||
import { startWith, takeUntil, map, debounce, debounceTime, throttleTime, filter } from 'rxjs/operators';
|
||||
|
||||
export const ops = {
|
||||
debounce,
|
||||
@ -13,4 +13,5 @@ export const ops = {
|
||||
startWith,
|
||||
takeUntil,
|
||||
throttleTime,
|
||||
filter,
|
||||
};
|
||||
|
Reference in New Issue
Block a user