@nitpicker/crawler 0.6.5-alpha.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,13 +28,19 @@ export async function fetchDestination(params) {
28
28
  return cache;
29
29
  }
30
30
  const effectiveMethod = titleBytesLimit == null ? method : 'GET';
31
+ // Race the fetch against a 10-second timeout. The losing timer is cleared
32
+ // explicitly so it never keeps the event loop alive after the race settles
33
+ // (a plain `delay()` in `Promise.race` would leak the timer until it fires).
34
+ let timeoutHandle;
31
35
  const result = await Promise.race([
32
36
  _fetchHead(url, isExternal, effectiveMethod, titleBytesLimit, userAgent).catch((error) => (error instanceof Error ? error : new Error(String(error)))),
33
- (async () => {
34
- await delay(10 * 1000);
35
- return new NetTimeoutError(url.href);
36
- })(),
37
- ]);
37
+ new Promise((resolve) => {
38
+ timeoutHandle = setTimeout(() => resolve(new NetTimeoutError(url.href)), 10 * 1000);
39
+ }),
40
+ ]).finally(() => {
41
+ if (timeoutHandle)
42
+ clearTimeout(timeoutHandle);
43
+ });
38
44
  destinationCache.set(cacheKey, result);
39
45
  if (result instanceof Error) {
40
46
  throw result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitpicker/crawler",
3
- "version": "0.6.5-alpha.0",
3
+ "version": "0.7.0",
4
4
  "description": "Web crawler engine with headless browser rendering and archive storage",
5
5
  "author": "D-ZERO",
6
6
  "license": "Apache-2.0",
@@ -48,5 +48,5 @@
48
48
  "@types/tar": "7.0.87",
49
49
  "@types/unzipper": "0.10.11"
50
50
  },
51
- "gitHead": "e084aba5a0887a80059ff8aa0608f61a58cc9288"
51
+ "gitHead": "3b4c33adf8af69a46a85faf8c04eddb5ab563972"
52
52
  }