Skip to content

Commit

Permalink
Properly clean up event listeners to avoid leaks
Browse files Browse the repository at this point in the history
It turns out warnings are good for something. We needed to remove the listeners if a timeout completes sucessfully, see nodejs/node#35990
  • Loading branch information
zner0L committed Nov 29, 2024
1 parent ca4da2b commit d2c8bbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
12 changes: 6 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ emulators running on the host.

#### Defined in

[util.ts:399](https://github.com/tweaselORG/appstraction/blob/main/src/util.ts#L399)
[util.ts:392](https://github.com/tweaselORG/appstraction/blob/main/src/util.ts#L392)

___

Expand Down Expand Up @@ -467,13 +467,13 @@ An object containing the parsed metadata, or `undefined` if the file doesn't exi

#### Defined in

[util.ts:78](https://github.com/tweaselORG/appstraction/blob/main/src/util.ts#L78)
[util.ts:71](https://github.com/tweaselORG/appstraction/blob/main/src/util.ts#L71)

___

### pause

**pause**(`durationInMs`, `abortSignal?`): `Promise`<`unknown`\>
**pause**(`durationInMs`, `abortSignal?`): `Promise`<`undefined`\>

Pause for a given duration.

Expand All @@ -482,15 +482,15 @@ Pause for a given duration.
| Name | Type | Description |
| :------ | :------ | :------ |
| `durationInMs` | `number` | The duration to pause for, in milliseconds. |
| `abortSignal?` | `AbortSignal` | - |
| `abortSignal?` | `AbortSignal` | Provide a signal to abort the pause. |

#### Returns

`Promise`<`unknown`\>
`Promise`<`undefined`\>

#### Defined in

[util.ts:52](https://github.com/tweaselORG/appstraction/blob/main/src/util.ts#L52)
[util.ts:54](https://github.com/tweaselORG/appstraction/blob/main/src/util.ts#L54)

___

Expand Down
13 changes: 3 additions & 10 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import timeout from 'p-timeout';
import { Certificate } from 'pkijs';
import type { Readable } from 'stream';
import { temporaryFile } from 'tempy';
import { setTimeout } from 'timers/promises';
import type { Entry, ZipFile } from 'yauzl';
import { fromFd } from 'yauzl';
import { venvOptions } from '../scripts/common/python';
Expand Down Expand Up @@ -48,18 +49,10 @@ export const retryCondition = async (
* Pause for a given duration.
*
* @param durationInMs The duration to pause for, in milliseconds.
* @param abortSignal Provide a signal to abort the pause.
*/
export const pause = (durationInMs: number, abortSignal?: AbortSignal) =>
new Promise((res, rej) => {
setTimeout(res, durationInMs);
if (abortSignal) {
const abortListener = () => {
abortSignal.removeEventListener('abort', abortListener);
rej(abortSignal.reason);
};
abortSignal?.addEventListener('abort', abortListener);
}
});
setTimeout(durationInMs, undefined, { signal: abortSignal });

/**
* Get metadata about the app at the given path.
Expand Down

0 comments on commit d2c8bbb

Please sign in to comment.