From 874bcb8e1113d23679efaded980fc113881a6c3a Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 3 Apr 2023 09:43:27 +0100 Subject: [PATCH 1/2] fix!: be explicit about sync/async behvaiour Crossing async boundaries is not free so allow the `Duplex` type to specify whether it is sync or async. BREAKING CHANGE: the `TSource` and `TSink` generic arguments to the `Duplex` type now refer to the stream type and not the type of objects yielded by the stream --- package.json | 3 ++- src/index.ts | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d7c80eb..22d792d 100644 --- a/package.json +++ b/package.json @@ -122,6 +122,7 @@ ] }, "scripts": { + "clean": "aegir clean", "lint": "aegir lint", "dep-check": "aegir dep-check", "build": "aegir build", @@ -129,6 +130,6 @@ "docs": "aegir docs" }, "devDependencies": { - "aegir": "^37.7.8" + "aegir": "^38.1.8" } } diff --git a/src/index.ts b/src/index.ts index 64ddaa8..7d8e1f0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ * It is a function that takes a source and returns a source. */ export interface Transform { - (source: Source): Source + (source: A): B } /** @@ -12,12 +12,18 @@ export interface Transform { * function that takes a source and iterates over it. It optionally returns * a value. */ -export interface Sink> { - (source: Source): R +export interface Sink> { + (source: Source): R } /** * A "source" is something that can be consumed. It is an iterable object. + * + * This type is a union of both sync and async sources - it is useful to keep + * code concise but declared types should prefer to specify whether they + * accept sync or async sources since treating a synchronous source as an + * asynchronous one can lead to performance degradation due to artificially + * induced asynchronous behaviour. */ export type Source = AsyncIterable | Iterable @@ -27,6 +33,6 @@ export type Source = AsyncIterable | Iterable * an object with two properties, sink and source. */ export interface Duplex> { - source: Source + source: TSource sink: Sink } From 84233f901479e741da6a14df9a7c99991b1d2e76 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 4 Apr 2023 09:53:39 +0100 Subject: [PATCH 2/2] chore: default tsource to unknown --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 7d8e1f0..b9512a3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,7 +32,7 @@ export type Source = AsyncIterable | Iterable * necessarily connected to the values that can be consumed from it. It is * an object with two properties, sink and source. */ -export interface Duplex> { +export interface Duplex> { source: TSource sink: Sink }