Skip to content

Commit

Permalink
Switch to ES2022
Browse files Browse the repository at this point in the history
  • Loading branch information
surol committed Sep 16, 2023
1 parent 6c40ead commit 5a7e836
Show file tree
Hide file tree
Showing 29 changed files with 103 additions and 112 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@run-z/exec-z",
"version": "1.4.2",
"version": "2.0.0-pre.0",
"description": "Abortable executions",
"keywords": [
"abortable",
Expand All @@ -25,7 +25,7 @@
},
"sideEffects": false,
"dependencies": {
"@proc7ts/primitives": "^3.0.2"
"@proc7ts/primitives": "^4.0.1"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand Down
2 changes: 1 addition & 1 deletion src/aborted-execution-error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from '@jest/globals';
import { AbortedZExecutionError } from './aborted-execution-error';
import { AbortedZExecutionError } from './aborted-execution-error.js';

describe('AbortedZExecutionError', () => {
describe('toString', () => {
Expand Down
5 changes: 1 addition & 4 deletions src/aborted-execution-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export class AbortedZExecutionError extends Error {
*/
constructor(readonly abortReason?: unknown, message = 'Execution aborted') {
super(abortReason !== undefined ? `${message}. ${abortReason}` : message);
}

get name(): string {
return 'Aborted';
this.name = 'Aborted';
}

}
8 changes: 4 additions & 4 deletions src/exec-after.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
import { asis } from '@proc7ts/primitives';
import type { Mock } from 'jest-mock';
import { AbortedZExecutionError } from './aborted-execution-error';
import { execZ } from './exec';
import { execZAfter } from './exec-after';
import type { ZExecution } from './execution';
import { AbortedZExecutionError } from './aborted-execution-error.js';
import { execZAfter } from './exec-after.js';
import { execZ } from './exec.js';
import type { ZExecution } from './execution.js';

describe('execZAfter', () => {
let first: ZExecution<string>;
Expand Down
12 changes: 6 additions & 6 deletions src/exec-after.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { noop } from '@proc7ts/primitives';
import { AbortedZExecutionError } from './aborted-execution-error';
import { execZ, ZExecutionStarter } from './exec';
import type { ZExecution } from './execution';
import { AbortedZExecutionError } from './aborted-execution-error.js';
import { execZ, ZExecutionStarter } from './exec.js';
import type { ZExecution } from './execution.js';

/**
* Performs execution after previous one succeed.
*
* @typeparam TFirstResult First execution result type.
* @typeparam TResult Second execution result type.
* @typeParam TFirstResult First execution result type.
* @typeParam TResult Second execution result type.
* @param first - Execution to complete first.
* @param next - Next execution starter function accepting result of the first execution as its argument.
*
Expand All @@ -29,7 +29,7 @@ export function execZAfter<TFirstResult, TResult>(
exec.abort();
};

return exec.whenDone();
return await exec.whenDone();
};

abort = (): void => {
Expand Down
6 changes: 3 additions & 3 deletions src/exec-all.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
import { asis, noop } from '@proc7ts/primitives';
import type { Mock } from 'jest-mock';
import { execZ } from './exec';
import { execZAll } from './exec-all';
import type { ZExecution } from './execution';
import { execZAll } from './exec-all.js';
import { execZ } from './exec.js';
import type { ZExecution } from './execution.js';

describe('execZAll', () => {
let done1: (value: string) => void;
Expand Down
20 changes: 10 additions & 10 deletions src/exec-all.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { asis, noop } from '@proc7ts/primitives';
import { execZ } from './exec';
import type { ZExecution } from './execution';
import { execZ } from './exec.js';
import type { ZExecution } from './execution.js';

/**
* Performs execution that succeeds when all the given executions do, or fails when either of them fail.
*
* Aborts other executions once one of them fail.
*
* @typeparam T1 First execution result type.
* @typeparam T2 Second execution result type.
* @typeParam T1 First execution result type.
* @typeParam T2 Second execution result type.
* @param executions - An iterable of executions.
*
* @returns New execution instance.
Expand All @@ -22,9 +22,9 @@ export function execZAll<T1, T2>(
*
* Aborts other executions once one of them fail.
*
* @typeparam T1 First execution result type.
* @typeparam T2 Second execution result type.
* @typeparam T Execution results combination type.
* @typeParam T1 First execution result type.
* @typeParam T2 Second execution result type.
* @typeParam T Execution results combination type.
* @param executions - An iterable of executions.
* @param combine - Combiner function accepting execution results array and returning their combination.
*
Expand Down Expand Up @@ -332,7 +332,7 @@ export function execZAll<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
*
* Aborts other executions once one of them fail.
*
* @typeparam TResult Executions result type.
* @typeParam TResult Executions result type.
* @param executions - An iterable of executions.
*
* @returns New execution instance.
Expand All @@ -345,8 +345,8 @@ export function execZAll<TResult>(executions: Iterable<ZExecution<TResult>>): ZE
*
* Aborts other executions once one of them fail.
*
* @typeparam TResult Executions result type.
* @typeparam TCombination Execution results combination type.
* @typeParam TResult Executions result type.
* @typeParam TCombination Execution results combination type.
* @param executions - An iterable of executions.
* @param combine - Combiner function accepting execution results array and returning their combination.
*
Expand Down
4 changes: 2 additions & 2 deletions src/exec-noop.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from '@jest/globals';
import { noop } from '@proc7ts/primitives';
import { execZNoOp } from './exec-noop';
import { immediateResolution } from './spec';
import { execZNoOp } from './exec-noop.js';
import { immediateResolution } from './spec/immediate-resolution.js';

describe('execZNoOp', () => {
describe('whenStarted', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/exec-noop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { noop } from '@proc7ts/primitives';
import { zExecutionDone } from './exec-done.impl';
import type { ZExecution } from './execution';
import { zExecutionDone } from './exec-done.impl.js';
import type { ZExecution } from './execution.js';

/**
* @internal
Expand All @@ -18,7 +18,7 @@ const noopZExecution: ZExecution = {
/**
* Performs no-op execution.
*
* @typeparam TResult Execution result type.
* @typeParam TResult Execution result type.
*
* @returns Already completed execution instance.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/exec.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals';
import { asis, noop } from '@proc7ts/primitives';
import type { Mock } from 'jest-mock';
import { AbortedZExecutionError } from './aborted-execution-error';
import { execZ } from './exec';
import type { ZExecution } from './execution';
import { AbortedZExecutionError } from './aborted-execution-error.js';
import { execZ } from './exec.js';
import type { ZExecution } from './execution.js';

describe('execZ', () => {
describe('whenStarted', () => {
Expand Down
38 changes: 19 additions & 19 deletions src/exec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { asyncByRecipe, lazyValue, noop, valueProvider } from '@proc7ts/primitives';
import { AbortedZExecutionError } from './aborted-execution-error';
import type { ZExecution } from './execution';
import { AbortedZExecutionError } from './aborted-execution-error.js';
import type { ZExecution } from './execution.js';

/**
* Execution starter signature.
*
* Constructs new execution initializer.
*
* @typeparam TResult Execution result type.
* @typeparam TArgs Starter arguments tuple type.
* @typeParam TResult Execution result type.
* @typeParam TArgs Starter arguments tuple type.
* @param args - Starter arguments.
*
* @returns Either execution initializer, or a promise-like instance resolving to one.
*/
export type ZExecutionStarter<TResult = void, TArgs extends any[] = []> =
/**
* @param args - Starter arguments.
*
* @returns Either execution initializer, or a promise-like instance resolving to one.
*/
(this: void, ...args: TArgs) => ZExecutionInit<TResult> | PromiseLike<ZExecutionInit<TResult>>;
export type ZExecutionStarter<TResult = void, TArgs extends any[] = []> = (
this: void,
...args: TArgs
) => ZExecutionInit<TResult> | PromiseLike<ZExecutionInit<TResult>>;

/**
* Execution initializer.
*
* Returned from {@link ZExecutionStarter execution starter} to construct new executions.
*
* @typeparam TResult Execution result type.
* @typeParam TResult Execution result type.
*/
export interface ZExecutionInit<TResult> {
/**
Expand Down Expand Up @@ -54,18 +54,18 @@ export interface ZExecutionInit<TResult> {
/**
* Starts execution by the given starter.
*
* @typeparam TResult Execution result type.
* @typeParam TResult Execution result type.
* @param starter - Execution starter function.
*
* @returns New execution instance to start by the given starter.
*/
export function execZ<TResult>(starter: ZExecutionStarter<TResult>): ZExecution<TResult> {
let start: () => void;
let dontStart: (error: unknown) => void;
let doNotStart: (error: unknown) => void;
let whenStarted = (): Promise<void> => {
const result = new Promise<void>((resolve, reject) => {
start = resolve;
dontStart = reject;
doNotStart = reject;
});

whenStarted = valueProvider(result);
Expand All @@ -76,7 +76,7 @@ export function execZ<TResult>(starter: ZExecutionStarter<TResult>): ZExecution<
start = () => {
whenStarted = valueProvider(Promise.resolve());
};
dontStart = (error: unknown): void => {
doNotStart = (error: unknown): void => {
whenStarted = lazyValue(() => Promise.reject(error));
};

Expand All @@ -86,7 +86,7 @@ export function execZ<TResult>(starter: ZExecutionStarter<TResult>): ZExecution<
initialize = init => {
init.abort?.();
};
dontStart(new AbortedZExecutionError());
doNotStart(new AbortedZExecutionError());
};

initialize = init => {
Expand All @@ -99,7 +99,7 @@ export function execZ<TResult>(starter: ZExecutionStarter<TResult>): ZExecution<
.then(() => init.whenStarted?.())
.then(
() => start(),
error => dontStart(error),
error => doNotStart(error),
);
};

Expand All @@ -114,7 +114,7 @@ export function execZ<TResult>(starter: ZExecutionStarter<TResult>): ZExecution<
return Promise.resolve(init.whenDone()).finally(done);
})
.catch(error => {
dontStart(error);
doNotStart(error);

return Promise.reject(error);
});
Expand Down
2 changes: 1 addition & 1 deletion src/execution.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Arbitrary execution that can be aborted.
*
* @typeparam TResult Execution result type.
* @typeParam TResult Execution result type.
*/
export interface ZExecution<TResult = void> {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/fail.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from '@jest/globals';
import { asis, noop } from '@proc7ts/primitives';
import { failZ } from './fail';
import { immediateResolution } from './spec';
import { failZ } from './fail.js';
import { immediateResolution } from './spec/immediate-resolution.js';

describe('failZ', () => {
describe('whenStarted', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/fail.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { noop } from '@proc7ts/primitives';
import { zExecutionDone } from './exec-done.impl';
import type { ZExecution } from './execution';
import { zExecutionDone } from './exec-done.impl.js';
import type { ZExecution } from './execution.js';

/**
* Performs failed execution.
Expand Down
2 changes: 1 addition & 1 deletion src/failed-execution-error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from '@jest/globals';
import { FailedZExecutionError } from './failed-execution-error';
import { FailedZExecutionError } from './failed-execution-error.js';

describe('FailedZExecutionError', () => {
describe('toString', () => {
Expand Down
4 changes: 1 addition & 3 deletions src/failed-execution-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ export class FailedZExecutionError extends Error {
*/
constructor(readonly failure?: unknown, message = 'Execution failed') {
super(failure !== undefined ? `${message}. ${failure}` : message);
}

get name(): string {
return 'Failed';
this.name = 'Failed';
}

}
16 changes: 0 additions & 16 deletions src/index.ts

This file was deleted.

16 changes: 16 additions & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @packageDocumentation
* @module @run-z/exec-z
*/
export * from './aborted-execution-error.js';
export * from './exec-after.js';
export * from './exec-all.js';
export * from './exec-noop.js';
export * from './exec.js';
export * from './execution.js';
export * from './fail.js';
export * from './failed-execution-error.js';
export * from './pool-executions.js';
export * from './resolve.js';
export * from './spawn-worker.js';
export * from './spawn.js';
6 changes: 3 additions & 3 deletions src/pool-executions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { beforeEach, describe, expect, it } from '@jest/globals';
import { asis } from '@proc7ts/primitives';
import { AbortedZExecutionError } from './aborted-execution-error';
import { execZ, ZExecutionStarter } from './exec';
import { poolZExecutions } from './pool-executions';
import { AbortedZExecutionError } from './aborted-execution-error.js';
import { execZ, ZExecutionStarter } from './exec.js';
import { poolZExecutions } from './pool-executions.js';

describe('poolZExecutions', () => {
let started: Set<number>;
Expand Down
10 changes: 5 additions & 5 deletions src/pool-executions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { noop } from '@proc7ts/primitives';
import os from 'node:os';
import { AbortedZExecutionError } from './aborted-execution-error';
import type { ZExecutionStarter } from './exec';
import { execZ } from './exec';
import type { ZExecution } from './execution';
import { failZ } from './fail';
import { AbortedZExecutionError } from './aborted-execution-error.js';
import type { ZExecutionStarter } from './exec.js';
import { execZ } from './exec.js';
import type { ZExecution } from './execution.js';
import { failZ } from './fail.js';

/**
* Constructs execution pool.
Expand Down
Loading

0 comments on commit 5a7e836

Please sign in to comment.