Skip to content

Commit

Permalink
fix: accept source as a sink input type
Browse files Browse the repository at this point in the history
To make it a bit more flexible
  • Loading branch information
achingbrain committed Apr 19, 2023
1 parent e1b5942 commit e6a1a42
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
]
},
"scripts": {
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
"build": "tsc",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ export function abortableSource <T> (source: Source<T>, signal: AbortSignal, opt
return abortable()
}

export function abortableSink <T, R = Promise<void>> (sink: Sink<AsyncIterable<T>, R>, signal: AbortSignal, options?: Options<T>): Sink<AsyncIterable<T>, R> {
export function abortableSink <T, R = Promise<void>> (sink: Sink<AsyncIterable<T>, R>, signal: AbortSignal, options?: Options<T>): Sink<Source<T>, R> {
return (source: Source<T>) => sink(abortableSource(source, signal, options))
}

export function abortableDuplex <TSource, TSink = TSource, RSink = Promise<void>> (duplex: Duplex<AsyncIterable<TSource>, AsyncIterable<TSink>, RSink>, signal: AbortSignal, options?: Options<TSource>): Duplex<AsyncGenerator<TSource>, AsyncIterable<TSink>, RSink> {
export function abortableDuplex <TSource, TSink = TSource, RSink = Promise<void>> (duplex: Duplex<AsyncIterable<TSource>, Source<TSink>, RSink>, signal: AbortSignal, options?: Options<TSource>): Duplex<AsyncGenerator<TSource>, Source<TSink>, RSink> {
return {
sink: abortableSink(duplex.sink, signal, {
...options,
Expand Down
6 changes: 3 additions & 3 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ describe('abortable-iterator', () => {

it('should abort a duplex used as a source', async () => {
const controller = new AbortController()
const duplex: Duplex<AsyncIterable<number>> = {
const duplex: Duplex<AsyncIterable<number>, Source<number>> = {
source: forever(),
sink: async (source) => { await drain(source) }
}
Expand All @@ -192,7 +192,7 @@ describe('abortable-iterator', () => {

it('should abort a duplex used as a transform', async () => {
const controller = new AbortController()
const duplex: Duplex<AsyncIterable<number>> = {
const duplex: Duplex<AsyncIterable<number>, Source<number>> = {
source: forever(),
sink: drain
}
Expand All @@ -210,7 +210,7 @@ describe('abortable-iterator', () => {

it('should abort a duplex used as a sink', async () => {
const controller = new AbortController()
const duplex: Duplex<AsyncIterable<number>> = {
const duplex: Duplex<AsyncIterable<number>, Source<number>> = {
source: forever(),
sink: drain
}
Expand Down

0 comments on commit e6a1a42

Please sign in to comment.