Kaynağa Gözat

improve types on source

Aurélien Richez 4 yıl önce
ebeveyn
işleme
b9edde9717
2 değiştirilmiş dosya ile 7 ekleme ve 3 silme
  1. 3 0
      src/Runnable.ts
  2. 4 3
      src/Source.ts

+ 3 - 0
src/Runnable.ts

@@ -0,0 +1,3 @@
+export interface Runnable<T> {
+  run(): Promise<T>
+}

+ 4 - 3
src/Source.ts

@@ -18,6 +18,7 @@ import {
 
 import { Sink } from './Sink'
 import { Flow } from './Flow'
+import { Runnable } from './Runnable'
 
 export class Source<T> extends LinearShape<T> {
   protected __phantom__!: T
@@ -30,11 +31,11 @@ export class Source<T> extends LinearShape<T> {
     return new Source(MappedStreamBuilder(this.builder, f))
   }
 
-  mapAsync<O>(concurrency: number, f: (v: T) => Promise<O>) {
+  mapAsync<O>(concurrency: number, f: (v: T) => Promise<O>): Source<O> {
     return new Source(MappedAsyncStreamBuilder(this.builder, concurrency < 1 ? 1 : 0 | concurrency, f))
   }
 
-  mapAsyncUnordered<O>(concurrency: number, f: (v: T) => Promise<O>) {
+  mapAsyncUnordered<O>(concurrency: number, f: (v: T) => Promise<O>): Source<O> {
     return new Source(MappedAsyncUnorderedStreamBuilder(this.builder, concurrency < 1 ? 1 : 0 | concurrency, f))
   }
 
@@ -73,7 +74,7 @@ export class Source<T> extends LinearShape<T> {
     return new Source(FlatMappedStreamBuilder(this.builder, (v: T) => f(v)[builderSymbol]))
   }
 
-  into<M>(sink: Sink<T, M>) {
+  into<M>(sink: Sink<T, M>): Runnable<M> {
     const self = this
     return {
       run() {