Skip to content

Commit

Permalink
style(stream-transform-from): update src/index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
sounisi5011 committed May 22, 2021
1 parent 8d33a5a commit c307fad
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions packages/stream-transform-from/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type IfNeverThenUnknown<T> = [T] extends [never] ? unknown : T;
* the chunk value is always an instance of Buffer.
*/
export type InputChunkType<T extends stream.TransformOptions> = (
true extends (GetPropValue<T, 'objectMode'> | GetPropValue<T, 'writableObjectMode'>) ? unknown : Buffer
true extends GetPropValue<T, 'objectMode' | 'writableObjectMode'> ? unknown : Buffer
);

/**
Expand Down Expand Up @@ -62,8 +62,14 @@ const DISALLOW_OPTION_NAMES = [
] as const;

function removeProp<T>(obj: T, props: readonly never[]): T;
function removeProp<T, K extends PropertyKey>(obj: T | undefined, props: readonly K[]): Omit<T, K> | undefined;
function removeProp<T, K extends PropertyKey>(obj: T | null, props: readonly K[]): Omit<T, K> | null;
function removeProp<T, K extends PropertyKey>(
obj: T | undefined,
props: readonly K[],
): Omit<T, K> | undefined;
function removeProp<T, K extends PropertyKey>(
obj: T | null,
props: readonly K[],
): Omit<T, K> | null;
function removeProp<T, K extends PropertyKey>(
obj: T | null | undefined,
props: readonly K[],
Expand Down Expand Up @@ -137,7 +143,9 @@ export class TransformFromAsyncIterable<
}
}

private callTransformCallback(...args: Parameters<stream.TransformCallback>): boolean {
private callTransformCallback(
...args: Parameters<stream.TransformCallback>
): boolean {
const { transformCallback } = this;
if (transformCallback) {
this.transformCallback = undefined;
Expand All @@ -149,10 +157,13 @@ export class TransformFromAsyncIterable<

private async *createSource(): SourceIterator<TOpts> {
while (true) {
const data = this.receivedDataList.shift() ?? await new Promise<ReceivedData<TOpts>>(resolve => {
this.receiveData = resolve;
this.callTransformCallback();
});
const data: ReceivedData<TOpts> = (
this.receivedDataList.shift()
?? await new Promise(resolve => {
this.receiveData = resolve;
this.callTransformCallback();
})
);
if (data.done) break;
const { done: _, ...chunkData } = data;
yield chunkData;
Expand All @@ -169,7 +180,9 @@ export class TransformFromAsyncIterable<
}
}

private emitFinishEventAfterCallback(flushCallback: stream.TransformCallback): stream.TransformCallback {
private emitFinishEventAfterCallback(
flushCallback: stream.TransformCallback,
): stream.TransformCallback {
const finishEventName = 'finish';
const finishEventList: unknown[][] = [];

Expand Down

0 comments on commit c307fad

Please sign in to comment.