Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: be explicit about sync/async behaviour #45

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@
]
},
"scripts": {
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"build": "aegir build",
"release": "aegir release",
"docs": "aegir docs"
},
"devDependencies": {
"aegir": "^37.7.8"
"aegir": "^38.1.8"
}
}
16 changes: 11 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@
* It is a function that takes a source and returns a source.
*/
export interface Transform<A, B = A> {
(source: Source<A>): Source<B>
(source: A): B
}

/**
* A "sink" is something that consumes (or drains) a source. It is a
* function that takes a source and iterates over it. It optionally returns
* a value.
*/
export interface Sink<T, R = Promise<void>> {
(source: Source<T>): R
export interface Sink<Source, R = Promise<void>> {
(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<T> = AsyncIterable<T> | Iterable<T>

Expand All @@ -26,7 +32,7 @@ export type Source<T> = AsyncIterable<T> | Iterable<T>
* necessarily connected to the values that can be consumed from it. It is
* an object with two properties, sink and source.
*/
export interface Duplex<TSource, TSink = TSource, RSink = Promise<void>> {
source: Source<TSource>
export interface Duplex<TSource = unknown, TSink = TSource, RSink = Promise<void>> {
source: TSource
sink: Sink<TSink, RSink>
}