Fix a few things

This commit is contained in:
Vanilagy
2026-02-03 16:01:46 +01:00
parent 3209363470
commit cab92c55ec
2 changed files with 10 additions and 5 deletions
+3
View File
@@ -506,6 +506,9 @@ type UrlSourceOptions = {
// in memory. Defaults to 8 MiB.
maxCacheSize?: number;
// The maximum number of parallel requests to use for fetching. Defaults to 2.
parallelism?: number;
// Used to provide a custom fetch function
fetchFn?: typeof fetch;
};
+7 -5
View File
@@ -343,7 +343,7 @@ export type UrlSourceOptions = {
/** The maximum number of bytes the cache is allowed to hold in memory. Defaults to 64 MiB. */
maxCacheSize?: number;
/** The maximum number of parallel workers to use for fetching. Defaults to 2. */
/** The maximum number of parallel requests to use for fetching. Defaults to 2. */
parallelism?: number;
/**
@@ -406,7 +406,7 @@ export class UrlSource extends Source {
) {
throw new TypeError('options.maxCacheSize, when provided, must be a non-negative number.');
}
if (options.parallelism !== undefined && (!isNumber(options.parallelism) || options.parallelism < 1)) {
if (options.parallelism !== undefined && (!Number.isInteger(options.parallelism) || options.parallelism < 1)) {
throw new TypeError('options.parallelism, when provided, must be a positive number.');
}
if (options.fetchFn !== undefined && typeof options.fetchFn !== 'function') {
@@ -420,11 +420,13 @@ export class UrlSource extends Source {
this._options = options;
this._getRetryDelay = options.getRetryDelay ?? DEFAULT_RETRY_DELAY;
this._orchestrator = new ReadOrchestrator({
maxCacheSize: options.maxCacheSize ?? (64 * 2 ** 20 /* 64 MiB */),
// Most files in the real-world have a single sequential access pattern, but having two in parallel can
// also happen
maxWorkerCount: options.parallelism ?? 2,
const DEFAULT_PARALLELISM = 2;
this._orchestrator = new ReadOrchestrator({
maxCacheSize: options.maxCacheSize ?? (64 * 2 ** 20 /* 64 MiB */),
maxWorkerCount: options.parallelism ?? DEFAULT_PARALLELISM,
runWorker: this._runWorker.bind(this),
prefetchProfile: PREFETCH_PROFILES.network,
});