Skip to content

Commit

Permalink
0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ovx committed Apr 6, 2024
1 parent 1e18b66 commit 74b0664
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cjs/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export declare function solveChallenge(challenge: string, salt: string, algorith
promise: Promise<Solution | null>;
controller: AbortController;
};
export declare function solveChallengeWorkers(workerScript: string | URL, concurrency: number, challenge: string, salt: string, algorithm?: string, max?: number, startNumber?: number): Promise<Solution | null>;
export declare function solveChallengeWorkers(workerScript: string | URL | (() => Worker), concurrency: number, challenge: string, salt: string, algorithm?: string, max?: number, startNumber?: number): Promise<Solution | null>;
11 changes: 8 additions & 3 deletions cjs/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ async function solveChallengeWorkers(workerScript, concurrency, challenge, salt,
throw new Error('Too many workers. Max. 16 allowed workers.');
}
for (let i = 0; i < concurrency; i++) {
workers.push(new Worker(workerScript, {
type: 'module',
}));
if (typeof workerScript === 'function') {
workers.push(workerScript());
}
else {
workers.push(new Worker(workerScript, {
type: 'module',
}));
}
}
const step = Math.ceil(max / concurrency);
const solutions = await Promise.all(workers.map((worker, i) => {
Expand Down
16 changes: 10 additions & 6 deletions deno_dist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function solveChallenge(
}

export async function solveChallengeWorkers(
workerScript: string | URL,
workerScript: string | URL | (() => Worker),
concurrency: number,
challenge: string,
salt: string,
Expand All @@ -108,11 +108,15 @@ export async function solveChallengeWorkers(
throw new Error('Too many workers. Max. 16 allowed workers.');
}
for (let i = 0; i < concurrency; i++) {
workers.push(
new Worker(workerScript, {
type: 'module',
})
);
if (typeof workerScript === 'function') {
workers.push(workerScript());
} else {
workers.push(
new Worker(workerScript, {
type: 'module',
})
);
}
}
const step = Math.ceil(max / concurrency);
const solutions = await Promise.all(
Expand Down
2 changes: 1 addition & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export declare function solveChallenge(challenge: string, salt: string, algorith
promise: Promise<Solution | null>;
controller: AbortController;
};
export declare function solveChallengeWorkers(workerScript: string | URL, concurrency: number, challenge: string, salt: string, algorithm?: string, max?: number, startNumber?: number): Promise<Solution | null>;
export declare function solveChallengeWorkers(workerScript: string | URL | (() => Worker), concurrency: number, challenge: string, salt: string, algorithm?: string, max?: number, startNumber?: number): Promise<Solution | null>;
11 changes: 8 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ export async function solveChallengeWorkers(workerScript, concurrency, challenge
throw new Error('Too many workers. Max. 16 allowed workers.');
}
for (let i = 0; i < concurrency; i++) {
workers.push(new Worker(workerScript, {
type: 'module',
}));
if (typeof workerScript === 'function') {
workers.push(workerScript());
}
else {
workers.push(new Worker(workerScript, {
type: 'module',
}));
}
}
const step = Math.ceil(max / concurrency);
const solutions = await Promise.all(workers.map((worker, i) => {
Expand Down
16 changes: 10 additions & 6 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function solveChallenge(
}

export async function solveChallengeWorkers(
workerScript: string | URL,
workerScript: string | URL | (() => Worker),
concurrency: number,
challenge: string,
salt: string,
Expand All @@ -108,11 +108,15 @@ export async function solveChallengeWorkers(
throw new Error('Too many workers. Max. 16 allowed workers.');
}
for (let i = 0; i < concurrency; i++) {
workers.push(
new Worker(workerScript, {
type: 'module',
})
);
if (typeof workerScript === 'function') {
workers.push(workerScript());
} else {
workers.push(
new Worker(workerScript, {
type: 'module',
})
);
}
}
const step = Math.ceil(max / concurrency);
const solutions = await Promise.all(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "altcha-lib",
"version": "0.1.3",
"version": "0.1.4",
"description": "A library for creating and verifying ALTCHA challenges for Node.js, Bun and Deno.",
"author": "Daniel Regeci",
"license": "MIT",
Expand Down
4 changes: 3 additions & 1 deletion tests/challenge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ describe('challenge', () => {
hmacKey,
});
const result = await solveChallengeWorkers(
'./lib/worker.ts',
() => new Worker('./lib/worker.ts', {
type: 'module',
}),
4,
challenge.challenge,
challenge.salt,
Expand Down

0 comments on commit 74b0664

Please sign in to comment.