-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from jokester/refine
Refine
- Loading branch information
Showing
33 changed files
with
236 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { liftA2 } from './promise'; | ||
|
||
describe('liftA2', () => { | ||
it('lifts a sync function to promise', async () => { | ||
const liftedPlus = liftA2((a: number, b: number) => a + b); | ||
const sum = await liftedPlus(3, Promise.resolve(5)); | ||
expect(sum).toEqual(8); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
/** | ||
* lift2 f to Promise | ||
*/ | ||
export function liftA2<T1, T2, T3>(f: (a1: T1, a2: T2) => T3) { | ||
async function transformed(pa1: PromiseLike<T1> | T1, pa2: PromiseLike<T2> | T2): Promise<T3> { | ||
const v1 = await pa1; | ||
const v2 = await pa2; | ||
return Promise.resolve(f(v1, v2)); | ||
} | ||
|
||
return transformed; | ||
} |
4 changes: 2 additions & 2 deletions
4
src/concurrency/promise-container.spec.ts → ...ete/concurrency/promise-container.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/concurrency/promise-container.ts → obsolete/concurrency/promise-container.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Read stream until end | ||
* @deprecated use 'node:stream/consumers' instead. | ||
* @see https://nodejs.org/api/webstreams.html#streamconsumersjsonstream | ||
*/ | ||
export function readStream(stream: NodeJS.ReadableStream | NodeJS.ReadStream): Promise<Buffer> { | ||
return new Promise<Buffer>((resolve, reject) => { | ||
const buffers = [] as Buffer[]; | ||
|
||
stream.once('end', () => resolve(Buffer.concat(buffers))); | ||
|
||
stream.on('error', reject); | ||
|
||
stream.on('data', (chunk: string | Buffer) => { | ||
if (Buffer.isBuffer(chunk)) { | ||
buffers.push(chunk); | ||
} /* (typeof chunk === "string") */ else { | ||
buffers.push(Buffer.from(chunk)); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.