fix(core): update
This commit is contained in:
@ -46,5 +46,3 @@ hi+wow
|
||||
hi+wow
|
||||
hi+wow
|
||||
hi+wow
|
||||
hi+wow
|
||||
hi+wow
|
||||
|
@ -4,6 +4,7 @@ import * as smartdelay from '@push.rocks/smartdelay';
|
||||
|
||||
async function testBackpressure() {
|
||||
const stream1 = new SmartDuplex({
|
||||
name: 'stream1',
|
||||
objectMode: true,
|
||||
handleBackpressure: true,
|
||||
writeFunction: async (chunk, tools) => {
|
||||
@ -12,25 +13,29 @@ async function testBackpressure() {
|
||||
}
|
||||
});
|
||||
const stream2 = new SmartDuplex({
|
||||
name: 'stream2',
|
||||
objectMode: true,
|
||||
handleBackpressure: true,
|
||||
writeFunction: async (chunk, tools) => {
|
||||
await new Promise(resolve => setTimeout(resolve, 100)); // Slow processing
|
||||
await new Promise(resolve => setTimeout(resolve, 1)); // Slow processing
|
||||
console.log(`processed chunk ${chunk} in stream 2`);
|
||||
return chunk;
|
||||
}
|
||||
}); // This stream processes data more slowly
|
||||
const stream3 = new SmartDuplex({
|
||||
handleBackpressure: false,
|
||||
objectMode: true,
|
||||
name: 'stream3',
|
||||
handleBackpressure: true,
|
||||
writeFunction: async (chunk, tools) => {
|
||||
console.log(`finished chunk ${chunk} in stream 3`);
|
||||
await new Promise(resolve => setTimeout(resolve, 200)); // Slow processing
|
||||
console.log(`processed chunk ${chunk} in stream 3`);
|
||||
}
|
||||
});
|
||||
|
||||
stream1.pipe(stream2).pipe(stream3);
|
||||
|
||||
let backpressured = false;
|
||||
for (let i = 1; i < 100; i++) {
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
const canContinue = stream1.write(`Chunk ${i}`, 'utf8');
|
||||
if (!canContinue) {
|
||||
backpressured = true;
|
||||
|
@ -23,26 +23,4 @@ tap.test('should create a SmartStream from a Buffer', async () => {
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should create a SmartStream from an Observable', async () => {
|
||||
const observableData = 'Observable test data';
|
||||
const testObservable = smartrx.rxjs.of(Buffer.from(observableData));
|
||||
|
||||
const smartStream = SmartDuplex.fromObservable(testObservable, {
|
||||
handleBackpressure: false,
|
||||
});
|
||||
|
||||
let receivedData = Buffer.alloc(0);
|
||||
|
||||
return new Promise<void>((resolve) => {
|
||||
smartStream.on('data', (chunk: Buffer) => {
|
||||
receivedData = Buffer.concat([receivedData, chunk]);
|
||||
});
|
||||
|
||||
smartStream.on('end', () => {
|
||||
expect(receivedData.toString()).toEqual(observableData);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
Reference in New Issue
Block a user