Skip to content

Commit

Permalink
fix: 🐛 allow different return type per racer
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 30, 2024
1 parent 949a1c4 commit ffc3b89
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/createRace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('concurrently executes only the first function', () => {
});

test('returns result of the function', () => {
const race = createRace<number>();
const race = createRace();
const fn1 = jest.fn(() => 1);
const fn2 = jest.fn(() => 2);
expect(fn1).toHaveBeenCalledTimes(0);
Expand Down
4 changes: 2 additions & 2 deletions src/createRace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
*
* @returns A "race" function that will only invoke the first function passed to it.
*/
export const createRace = <T>() => {
export const createRace = () => {
let invoked: boolean = false;
return (fn: () => T): T | undefined => {
return <T>(fn: () => T): T | undefined => {
if (invoked) return;
invoked = true;
try {
Expand Down

0 comments on commit ffc3b89

Please sign in to comment.