@jonloucks/concurrency-ts 0.4.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.
- package/README.md +248 -0
- package/api/Completable.d.ts +51 -0
- package/api/Completable.d.ts.map +1 -0
- package/api/Completable.js +11 -0
- package/api/Completable.js.map +1 -0
- package/api/CompletableFactory.d.ts +29 -0
- package/api/CompletableFactory.d.ts.map +1 -0
- package/api/CompletableFactory.js +19 -0
- package/api/CompletableFactory.js.map +1 -0
- package/api/Completion.d.ts +18 -0
- package/api/Completion.d.ts.map +1 -0
- package/api/Completion.js +2 -0
- package/api/Completion.js.map +1 -0
- package/api/CompletionNotify.d.ts +23 -0
- package/api/CompletionNotify.d.ts.map +1 -0
- package/api/CompletionNotify.js +11 -0
- package/api/CompletionNotify.js.map +1 -0
- package/api/CompletionState.d.ts +35 -0
- package/api/CompletionState.d.ts.map +1 -0
- package/api/CompletionState.js +64 -0
- package/api/CompletionState.js.map +1 -0
- package/api/Concurrency.d.ts +90 -0
- package/api/Concurrency.d.ts.map +1 -0
- package/api/Concurrency.js +19 -0
- package/api/Concurrency.js.map +1 -0
- package/api/ConcurrencyException.d.ts +27 -0
- package/api/ConcurrencyException.d.ts.map +1 -0
- package/api/ConcurrencyException.js +53 -0
- package/api/ConcurrencyException.js.map +1 -0
- package/api/ConcurrencyFactory.d.ts +41 -0
- package/api/ConcurrencyFactory.d.ts.map +1 -0
- package/api/ConcurrencyFactory.js +19 -0
- package/api/ConcurrencyFactory.js.map +1 -0
- package/api/IsCompleted.d.ts +20 -0
- package/api/IsCompleted.d.ts.map +1 -0
- package/api/IsCompleted.js +11 -0
- package/api/IsCompleted.js.map +1 -0
- package/api/OnCompletion.d.ts +23 -0
- package/api/OnCompletion.d.ts.map +1 -0
- package/api/OnCompletion.js +12 -0
- package/api/OnCompletion.js.map +1 -0
- package/api/Rule.d.ts +28 -0
- package/api/Rule.d.ts.map +1 -0
- package/api/Rule.js +11 -0
- package/api/Rule.js.map +1 -0
- package/api/StateMachine.d.ts +95 -0
- package/api/StateMachine.d.ts.map +1 -0
- package/api/StateMachine.js +13 -0
- package/api/StateMachine.js.map +1 -0
- package/api/StateMachineFactory.d.ts +29 -0
- package/api/StateMachineFactory.d.ts.map +1 -0
- package/api/StateMachineFactory.js +19 -0
- package/api/StateMachineFactory.js.map +1 -0
- package/api/TimeoutException.d.ts +21 -0
- package/api/TimeoutException.d.ts.map +1 -0
- package/api/TimeoutException.js +27 -0
- package/api/TimeoutException.js.map +1 -0
- package/api/Transition.d.ts +44 -0
- package/api/Transition.d.ts.map +1 -0
- package/api/Transition.js +11 -0
- package/api/Transition.js.map +1 -0
- package/api/Types.d.ts +27 -0
- package/api/Types.d.ts.map +1 -0
- package/api/Types.js +28 -0
- package/api/Types.js.map +1 -0
- package/api/Waitable.d.ts +39 -0
- package/api/Waitable.d.ts.map +1 -0
- package/api/Waitable.js +17 -0
- package/api/Waitable.js.map +1 -0
- package/api/WaitableConsumer.d.ts +54 -0
- package/api/WaitableConsumer.d.ts.map +1 -0
- package/api/WaitableConsumer.js +11 -0
- package/api/WaitableConsumer.js.map +1 -0
- package/api/WaitableFactory.d.ts +29 -0
- package/api/WaitableFactory.d.ts.map +1 -0
- package/api/WaitableFactory.js +19 -0
- package/api/WaitableFactory.js.map +1 -0
- package/api/WaitableNotify.d.ts +31 -0
- package/api/WaitableNotify.d.ts.map +1 -0
- package/api/WaitableNotify.js +12 -0
- package/api/WaitableNotify.js.map +1 -0
- package/api/WaitableSupplier.d.ts +53 -0
- package/api/WaitableSupplier.d.ts.map +1 -0
- package/api/WaitableSupplier.js +11 -0
- package/api/WaitableSupplier.js.map +1 -0
- package/auxiliary/Checks.d.ts +116 -0
- package/auxiliary/Checks.d.ts.map +1 -0
- package/auxiliary/Checks.js +145 -0
- package/auxiliary/Checks.js.map +1 -0
- package/auxiliary/Consumer.d.ts +45 -0
- package/auxiliary/Consumer.d.ts.map +1 -0
- package/auxiliary/Consumer.js +45 -0
- package/auxiliary/Consumer.js.map +1 -0
- package/auxiliary/Predicate.d.ts +55 -0
- package/auxiliary/Predicate.d.ts.map +1 -0
- package/auxiliary/Predicate.js +73 -0
- package/auxiliary/Predicate.js.map +1 -0
- package/auxiliary/Supplier.d.ts +52 -0
- package/auxiliary/Supplier.d.ts.map +1 -0
- package/auxiliary/Supplier.js +67 -0
- package/auxiliary/Supplier.js.map +1 -0
- package/impl/Completable.impl.d.ts +10 -0
- package/impl/Completable.impl.d.ts.map +1 -0
- package/impl/Completable.impl.js +136 -0
- package/impl/Completable.impl.js.map +1 -0
- package/impl/CompletableFactory.impl.d.ts +9 -0
- package/impl/CompletableFactory.impl.d.ts.map +1 -0
- package/impl/CompletableFactory.impl.js +42 -0
- package/impl/CompletableFactory.impl.js.map +1 -0
- package/impl/CompleteLater.impl.d.ts +12 -0
- package/impl/CompleteLater.impl.d.ts.map +1 -0
- package/impl/CompleteLater.impl.js +31 -0
- package/impl/CompleteLater.impl.js.map +1 -0
- package/impl/CompleteNow.impl.d.ts +14 -0
- package/impl/CompleteNow.impl.d.ts.map +1 -0
- package/impl/CompleteNow.impl.js +33 -0
- package/impl/CompleteNow.impl.js.map +1 -0
- package/impl/Concurrency.impl.d.ts +9 -0
- package/impl/Concurrency.impl.d.ts.map +1 -0
- package/impl/Concurrency.impl.js +84 -0
- package/impl/Concurrency.impl.js.map +1 -0
- package/impl/ConcurrencyFactory.impl.d.ts +10 -0
- package/impl/ConcurrencyFactory.impl.d.ts.map +1 -0
- package/impl/ConcurrencyFactory.impl.js +74 -0
- package/impl/ConcurrencyFactory.impl.js.map +1 -0
- package/impl/ConcurrencyWrapper.impl.d.ts +13 -0
- package/impl/ConcurrencyWrapper.impl.d.ts.map +1 -0
- package/impl/ConcurrencyWrapper.impl.js +85 -0
- package/impl/ConcurrencyWrapper.impl.js.map +1 -0
- package/impl/Events.d.ts +25 -0
- package/impl/Events.d.ts.map +1 -0
- package/impl/Events.impl.d.ts +11 -0
- package/impl/Events.impl.d.ts.map +1 -0
- package/impl/Events.impl.js +63 -0
- package/impl/Events.impl.js.map +1 -0
- package/impl/Events.js +3 -0
- package/impl/Events.js.map +1 -0
- package/impl/ExposedPromise.d.ts +26 -0
- package/impl/ExposedPromise.d.ts.map +1 -0
- package/impl/ExposedPromise.impl.d.ts +9 -0
- package/impl/ExposedPromise.impl.d.ts.map +1 -0
- package/impl/ExposedPromise.impl.js +41 -0
- package/impl/ExposedPromise.impl.js.map +1 -0
- package/impl/ExposedPromise.js +2 -0
- package/impl/ExposedPromise.js.map +1 -0
- package/impl/Internal.impl.d.ts +35 -0
- package/impl/Internal.impl.d.ts.map +1 -0
- package/impl/Internal.impl.js +90 -0
- package/impl/Internal.impl.js.map +1 -0
- package/impl/StateMachine.impl.d.ts +9 -0
- package/impl/StateMachine.impl.d.ts.map +1 -0
- package/impl/StateMachine.impl.js +184 -0
- package/impl/StateMachine.impl.js.map +1 -0
- package/impl/StateMachineFactory.impl.d.ts +9 -0
- package/impl/StateMachineFactory.impl.d.ts.map +1 -0
- package/impl/StateMachineFactory.impl.js +43 -0
- package/impl/StateMachineFactory.impl.js.map +1 -0
- package/impl/Waitable.impl.d.ts +8 -0
- package/impl/Waitable.impl.d.ts.map +1 -0
- package/impl/Waitable.impl.js +212 -0
- package/impl/Waitable.impl.js.map +1 -0
- package/impl/WaitableFactory.impl.d.ts +9 -0
- package/impl/WaitableFactory.impl.d.ts.map +1 -0
- package/impl/WaitableFactory.impl.js +42 -0
- package/impl/WaitableFactory.impl.js.map +1 -0
- package/index.d.ts +25 -0
- package/index.d.ts.map +1 -0
- package/index.js +33 -0
- package/index.js.map +1 -0
- package/package.json +88 -0
- package/version.d.ts +3 -0
- package/version.d.ts.map +1 -0
- package/version.js +4 -0
- package/version.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# @jonloucks/concurrency-ts
|
|
2
|
+
|
|
3
|
+
## Badges
|
|
4
|
+
[](https://github.com/jonloucks/concurrency-ts/actions)
|
|
5
|
+
[](https://www.npmjs.com/package/@jonloucks/concurrency-ts)
|
|
6
|
+
[](https://jonloucks.github.io/concurrency-ts/lcov-report/)
|
|
7
|
+
[](https://jonloucks.github.io/concurrency-ts/typedoc/)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
A TypeScript library that provides powerful abstractions for managing asynchronous concurrency, state machines, and completion patterns. It offers type-safe primitives for building concurrent applications with guaranteed completion semantics.
|
|
11
|
+
|
|
12
|
+
## Key Features
|
|
13
|
+
|
|
14
|
+
- **Type-safe concurrency primitives** - Fully typed interfaces for concurrent operations
|
|
15
|
+
- **Waitable references** - Thread-safe mutable references that allow waiting for condition changes
|
|
16
|
+
- **Completables** - Observe activities from start to finish with guaranteed completion
|
|
17
|
+
- **State machines** - User-defined states with transition rules and validation
|
|
18
|
+
- **Guaranteed execution** - Patterns ensuring completion callbacks are always invoked
|
|
19
|
+
- **Resource management** - Automatic cleanup via the `Open` interface
|
|
20
|
+
|
|
21
|
+
## Documentation
|
|
22
|
+
* [Complete Documentation](DOCUMENTATION.md) - **Comprehensive guide with examples**
|
|
23
|
+
* [License](LICENSE.md)
|
|
24
|
+
* [Contributing](CONTRIBUTING.md)
|
|
25
|
+
* [Code of conduct](CODE_OF_CONDUCT.md)
|
|
26
|
+
* [Coding standards](CODING_STANDARDS.md)
|
|
27
|
+
* [Security policy](SECURITY.md)
|
|
28
|
+
* [Pull request template](PULL_REQUEST_TEMPLATE.md)
|
|
29
|
+
* [How to use API](https://jonloucks.github.io/concurrency-ts/typedoc/)
|
|
30
|
+
* [Test coverage report](https://jonloucks.github.io/concurrency-ts/lcov-report)
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @jonloucks/concurrency-ts
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
For comprehensive examples and detailed API documentation, see [DOCUMENTATION.md](DOCUMENTATION.md).
|
|
41
|
+
|
|
42
|
+
### Quick Start
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { createConcurrency, Waitable, Completable, StateMachine } from '@jonloucks/concurrency-ts';
|
|
46
|
+
|
|
47
|
+
// Create a Concurrency instance
|
|
48
|
+
const concurrency = createConcurrency({});
|
|
49
|
+
using closeConcurrency = concurrency.open();
|
|
50
|
+
|
|
51
|
+
// Create a Waitable for thread-safe value storage
|
|
52
|
+
const waitable: Waitable<number> = concurrency.createWaitable({ initialValue: 0 });
|
|
53
|
+
using closeWaitable = waitable.open();
|
|
54
|
+
|
|
55
|
+
waitable.consume(42);
|
|
56
|
+
console.log(waitable.supply()); // 42
|
|
57
|
+
|
|
58
|
+
// Create a Completable to track async operations
|
|
59
|
+
const completable: Completable<string> = concurrency.createCompletable({});
|
|
60
|
+
using closeCompletable = completable.open();
|
|
61
|
+
|
|
62
|
+
completable.onCompletion((completion) => {
|
|
63
|
+
console.log('Task completed:', completion.state, completion.value);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
completable.notify({ state: 'SUCCEEDED', value: 'Done!' });
|
|
67
|
+
|
|
68
|
+
// Create a StateMachine for state management
|
|
69
|
+
type AppState = 'IDLE' | 'RUNNING' | 'STOPPED';
|
|
70
|
+
|
|
71
|
+
const stateMachine: StateMachine<AppState> = concurrency.createStateMachine({
|
|
72
|
+
initialValue: 'IDLE',
|
|
73
|
+
states: ['IDLE', 'RUNNING', 'STOPPED'],
|
|
74
|
+
getStateRules: (state) => {
|
|
75
|
+
switch (state) {
|
|
76
|
+
case 'IDLE':
|
|
77
|
+
return [{ event: 'start', allowedStates: ['RUNNING'] }];
|
|
78
|
+
case 'RUNNING':
|
|
79
|
+
return [{ event: 'stop', allowedStates: ['STOPPED'] }];
|
|
80
|
+
default:
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
using closeStateMachine = stateMachine.open();
|
|
87
|
+
|
|
88
|
+
console.log(stateMachine.getState()); // 'IDLE'
|
|
89
|
+
stateMachine.setState('start', 'RUNNING');
|
|
90
|
+
console.log(stateMachine.getState()); // 'RUNNING'
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
See [DOCUMENTATION.md](DOCUMENTATION.md) for more examples and advanced usage patterns.
|
|
94
|
+
|
|
95
|
+
## Development
|
|
96
|
+
|
|
97
|
+
<details markdown="1"><summary>Install dependencies</summary>
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm install
|
|
101
|
+
```
|
|
102
|
+
</details>
|
|
103
|
+
|
|
104
|
+
<details markdown="1"><summary>Build the project</summary>
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm run build
|
|
108
|
+
```
|
|
109
|
+
</details>
|
|
110
|
+
|
|
111
|
+
<details markdown="1"><summary>Run tests</summary>
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npm test
|
|
115
|
+
```
|
|
116
|
+
</details>
|
|
117
|
+
|
|
118
|
+
<details markdown="1"><summary>Run tests in watch mode</summary>
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
npm run test:watch
|
|
122
|
+
```
|
|
123
|
+
</details>
|
|
124
|
+
|
|
125
|
+
<details markdown="1"><summary>Run test coverage</summary>
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npm run test:coverage
|
|
129
|
+
```
|
|
130
|
+
</details>
|
|
131
|
+
|
|
132
|
+
<details markdown="1"><summary>Lint the code</summary>
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npm run lint
|
|
136
|
+
```
|
|
137
|
+
</details>
|
|
138
|
+
|
|
139
|
+
<details markdown="1"><summary>Fix linting issues</summary>
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
npm run lint:fix
|
|
143
|
+
```
|
|
144
|
+
</details>
|
|
145
|
+
|
|
146
|
+
<details markdown="1"><summary>Generate documents</summary>
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
npm run docs
|
|
150
|
+
```
|
|
151
|
+
</details>
|
|
152
|
+
|
|
153
|
+
<details markdown="1"><summary>Generate badges</summary>
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm run badges
|
|
157
|
+
```
|
|
158
|
+
</details>
|
|
159
|
+
|
|
160
|
+
<details markdown="1"><summary>Project Structure</summary>
|
|
161
|
+
|
|
162
|
+
* All tests must have suffix of -test.ts or -spec.ts
|
|
163
|
+
* Tests that validate supported APIs go in src/test
|
|
164
|
+
* Tests that validate internal implementation details go in src/impl
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
concurrency-ts
|
|
168
|
+
├── .github
|
|
169
|
+
│ ├── ISSUE_TEMPLATE
|
|
170
|
+
│ │ ├── bug_report.md
|
|
171
|
+
│ │ └── feature_request.md
|
|
172
|
+
│ └── workflows
|
|
173
|
+
│ ├── main-pull-request-matrix.yml
|
|
174
|
+
│ ├── main-pull-request.yml
|
|
175
|
+
│ ├── main-push.yml
|
|
176
|
+
│ └── main-release.yml
|
|
177
|
+
├── CODE_OF_CONDUCT.md
|
|
178
|
+
├── CODING_STANDARDS.md
|
|
179
|
+
├── CONTRIBUTING.md
|
|
180
|
+
├── editorconfig
|
|
181
|
+
├── eslint.config.mjs
|
|
182
|
+
├── jest.config.js
|
|
183
|
+
├── LICENSE
|
|
184
|
+
├── package-lock.json
|
|
185
|
+
├── package.json
|
|
186
|
+
├── PULL_REQUEST_TEMPLATE.md
|
|
187
|
+
├── README.md
|
|
188
|
+
├── scripts
|
|
189
|
+
│ ├── badge-template.svg.dat
|
|
190
|
+
│ └── tsconfig.json
|
|
191
|
+
├── SECURITY.md
|
|
192
|
+
├── src
|
|
193
|
+
│ ├── index.ts
|
|
194
|
+
│ ├── version.ts
|
|
195
|
+
│ ├── api
|
|
196
|
+
│ │ ├── *.ts
|
|
197
|
+
│ │ ├── *.api.ts
|
|
198
|
+
│ ├── auxiliary
|
|
199
|
+
│ │ ├── *.ts
|
|
200
|
+
│ │ ├── *.impl.ts
|
|
201
|
+
│ │ ├── *.test.ts // internal implementation specific
|
|
202
|
+
│ │ └── *.api.ts
|
|
203
|
+
│ ├── impl
|
|
204
|
+
│ │ ├── *.ts
|
|
205
|
+
│ │ ├── *.impl.ts
|
|
206
|
+
│ │ ├── *.test.ts // internal implementation specific
|
|
207
|
+
│ │ └── *.api.ts
|
|
208
|
+
│ ├── test
|
|
209
|
+
│ │ └── *.test.ts
|
|
210
|
+
│ └── never-publish // non shippable development scripts
|
|
211
|
+
│ ├── *.ts
|
|
212
|
+
│ ├── *.*. // data files etc
|
|
213
|
+
│ └── *.test.ts
|
|
214
|
+
├── tsconfig.json
|
|
215
|
+
└── typedoc.json
|
|
216
|
+
```
|
|
217
|
+
</details>
|
|
218
|
+
|
|
219
|
+
## GitHub Workflows
|
|
220
|
+
|
|
221
|
+
<details markdown="1"><summary>CI Workflow</summary>
|
|
222
|
+
|
|
223
|
+
The CI workflow runs on every push and pull request to `main` branch. It:
|
|
224
|
+
- Tests against Node.js versions 18.x, 20.x, and 22.x
|
|
225
|
+
- Runs linting
|
|
226
|
+
- Builds the project
|
|
227
|
+
- Runs tests with coverage
|
|
228
|
+
- Uploads coverage to Codecov (optional)
|
|
229
|
+
|
|
230
|
+
</details>
|
|
231
|
+
|
|
232
|
+
<details markdown="1"><summary>Publish Workflow</summary>
|
|
233
|
+
|
|
234
|
+
The GitHub publishings workflows are run to make an official release.
|
|
235
|
+
- If all scanning and tests pass it is published. There is no other way allowed.
|
|
236
|
+
- Publishing authentication is done using ([OIDC trusted publishing](https://docs.npmjs.com/trusted-publishers))
|
|
237
|
+
|
|
238
|
+
To set up your own publishing:
|
|
239
|
+
1. Publishing this project as is intentionally disabled
|
|
240
|
+
2. You are welcome to fork this repository and publish where you want.
|
|
241
|
+
3. Run `npm pkg delete private` to remove the `private` flag from the package.
|
|
242
|
+
4. Change the `name` field in `package.json` to your desired package name.
|
|
243
|
+
|
|
244
|
+
</details>
|
|
245
|
+
|
|
246
|
+
## License
|
|
247
|
+
|
|
248
|
+
MIT
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Completion, CompletionState } from "@jonloucks/concurrency-ts/api/Completion";
|
|
2
|
+
import { CompletionNotify } from "@jonloucks/concurrency-ts/api/CompletionNotify";
|
|
3
|
+
import { IsCompleted } from "@jonloucks/concurrency-ts/api/IsCompleted";
|
|
4
|
+
import { OnCompletion } from "@jonloucks/concurrency-ts/api/OnCompletion";
|
|
5
|
+
import { OptionalType, RequiredType } from "@jonloucks/concurrency-ts/api/Types";
|
|
6
|
+
import { WaitableNotify } from "@jonloucks/concurrency-ts/api/WaitableNotify";
|
|
7
|
+
import { Contracts } from "@jonloucks/contracts-ts/api/Contracts";
|
|
8
|
+
import { Open } from "@jonloucks/contracts-ts/api/Open";
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for a Completable
|
|
11
|
+
*
|
|
12
|
+
* @param <T> the type of completion value
|
|
13
|
+
*/
|
|
14
|
+
export interface Config<T> {
|
|
15
|
+
/**
|
|
16
|
+
* Optional contracts for validation or other purposes
|
|
17
|
+
*/
|
|
18
|
+
contracts?: Contracts;
|
|
19
|
+
/**
|
|
20
|
+
* Optional initial value for the completable
|
|
21
|
+
*/
|
|
22
|
+
initialValue?: OptionalType<T>;
|
|
23
|
+
}
|
|
24
|
+
export { type Config as CompletableConfig };
|
|
25
|
+
/**
|
|
26
|
+
* Responsibility: Observe a single activity from start to finish
|
|
27
|
+
*
|
|
28
|
+
* @param <T> the type of completion value
|
|
29
|
+
*/
|
|
30
|
+
export interface Completable<T> extends Open, CompletionNotify<T>, OnCompletion<T>, IsCompleted {
|
|
31
|
+
/**
|
|
32
|
+
* @return observe state change
|
|
33
|
+
*/
|
|
34
|
+
notifyState(): WaitableNotify<CompletionState>;
|
|
35
|
+
/**
|
|
36
|
+
* @return Observe the completed value
|
|
37
|
+
*/
|
|
38
|
+
notifyValue(): WaitableNotify<T>;
|
|
39
|
+
/**
|
|
40
|
+
* @return the current completion state
|
|
41
|
+
*/
|
|
42
|
+
getCompletion(): OptionalType<Completion<T>>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Determine if an instance implements Completable
|
|
46
|
+
*
|
|
47
|
+
* @param instance the instance to check
|
|
48
|
+
* @returns true if the instance implements Completable
|
|
49
|
+
*/
|
|
50
|
+
export declare function guard<T>(instance: unknown): instance is RequiredType<Completable<T>>;
|
|
51
|
+
//# sourceMappingURL=Completable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Completable.d.ts","sourceRoot":"","sources":["../../src/api/Completable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,YAAY,EAAkB,MAAM,qCAAqC,CAAC;AACjG,OAAO,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,kCAAkC,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;CAChC;AAED,OAAO,EAAE,KAAK,MAAM,IAAI,iBAAiB,EAAE,CAAC;AAE5C;;;;GAIG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,CAAE,SAAQ,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,WAAW;IAE7F;;OAEG;IACH,WAAW,IAAI,cAAc,CAAC,eAAe,CAAC,CAAC;IAE/C;;OAEG;IACH,WAAW,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;IAEjC;;OAEG;IACH,aAAa,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9C;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAUpF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { guardFunctions } from "@jonloucks/concurrency-ts/api/Types";
|
|
2
|
+
/**
|
|
3
|
+
* Determine if an instance implements Completable
|
|
4
|
+
*
|
|
5
|
+
* @param instance the instance to check
|
|
6
|
+
* @returns true if the instance implements Completable
|
|
7
|
+
*/
|
|
8
|
+
export function guard(instance) {
|
|
9
|
+
return guardFunctions(instance, 'open', 'notifyState', 'notifyValue', 'getCompletion', 'isCompleted', 'onCompletion', 'notify');
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=Completable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Completable.js","sourceRoot":"","sources":["../../src/api/Completable.ts"],"names":[],"mappings":"AAIA,OAAO,EAA8B,cAAc,EAAE,MAAM,qCAAqC,CAAC;AA+CjG;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAI,QAAiB;IACxC,OAAO,cAAc,CAAC,QAAQ,EAC5B,MAAM,EACN,aAAa,EACb,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,EACd,QAAQ,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Completable, Config } from "@jonloucks/concurrency-ts/api/Completable";
|
|
2
|
+
import { Contract } from "@jonloucks/contracts-ts";
|
|
3
|
+
import { RequiredType } from "@jonloucks/concurrency-ts/api/Types";
|
|
4
|
+
export { type Completable, type Config } from "@jonloucks/concurrency-ts/api/Completable";
|
|
5
|
+
/**
|
|
6
|
+
* Responsibility: Creating a new Completable
|
|
7
|
+
*/
|
|
8
|
+
export interface CompletableFactory {
|
|
9
|
+
/**
|
|
10
|
+
* Create a new Completable
|
|
11
|
+
*
|
|
12
|
+
* @param config the completable configuration
|
|
13
|
+
* @return the new Completable
|
|
14
|
+
* @param <T> the type of completion value
|
|
15
|
+
*/
|
|
16
|
+
createCompletable<T>(config?: Config<T>): Completable<T>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Determine if an instance implements CompletableFactory
|
|
20
|
+
*
|
|
21
|
+
* @param instance the instance to check
|
|
22
|
+
* @returns true if the instance implements CompletableFactory
|
|
23
|
+
*/
|
|
24
|
+
export declare function guard(instance: unknown): instance is RequiredType<CompletableFactory>;
|
|
25
|
+
/**
|
|
26
|
+
* The CompletableFactory contract
|
|
27
|
+
*/
|
|
28
|
+
export declare const CONTRACT: Contract<CompletableFactory>;
|
|
29
|
+
//# sourceMappingURL=CompletableFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompletableFactory.d.ts","sourceRoot":"","sources":["../../src/api/CompletableFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAkB,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAkB,MAAM,qCAAqC,CAAC;AAEnF,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAE1F;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAEjC;;;;;;OAMG;IACH,iBAAiB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;CACzD;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,kBAAkB,CAAC,CAErF;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,kBAAkB,CAGhD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createContract } from "@jonloucks/contracts-ts";
|
|
2
|
+
import { guardFunctions } from "@jonloucks/concurrency-ts/api/Types";
|
|
3
|
+
/**
|
|
4
|
+
* Determine if an instance implements CompletableFactory
|
|
5
|
+
*
|
|
6
|
+
* @param instance the instance to check
|
|
7
|
+
* @returns true if the instance implements CompletableFactory
|
|
8
|
+
*/
|
|
9
|
+
export function guard(instance) {
|
|
10
|
+
return guardFunctions(instance, 'createCompletable');
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The CompletableFactory contract
|
|
14
|
+
*/
|
|
15
|
+
export const CONTRACT = createContract({
|
|
16
|
+
name: "CompletableFactory",
|
|
17
|
+
test: guard
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=CompletableFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompletableFactory.js","sourceRoot":"","sources":["../../src/api/CompletableFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAgB,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAmBnF;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,QAAiB;IACrC,OAAO,cAAc,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;AACvD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAiC,cAAc,CAAC;IACnE,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,KAAK;CACZ,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OptionalType, RequiredType, Throwable } from "@jonloucks/concurrency-ts/api/Types";
|
|
2
|
+
import { CompletionState } from "@jonloucks/concurrency-ts/api/CompletionState";
|
|
3
|
+
export { type CompletionState };
|
|
4
|
+
/** Completion
|
|
5
|
+
*
|
|
6
|
+
* @param <T> the type of completion value
|
|
7
|
+
*/
|
|
8
|
+
export interface Completion<T> {
|
|
9
|
+
/** The completion state */
|
|
10
|
+
state: RequiredType<CompletionState>;
|
|
11
|
+
/** The optional thrown exception */
|
|
12
|
+
thrown?: OptionalType<Throwable<unknown>>;
|
|
13
|
+
/** The optional completion value */
|
|
14
|
+
value?: OptionalType<T>;
|
|
15
|
+
/** The optional associated Future */
|
|
16
|
+
promise?: OptionalType<Promise<T>>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=Completion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Completion.d.ts","sourceRoot":"","sources":["../../src/api/Completion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAEhF,OAAO,EAAE,KAAK,eAAe,EAAE,CAAC;AAEhC;;;GAGG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC;IAE3B,2BAA2B;IAC3B,KAAK,EAAE,YAAY,CAAC,eAAe,CAAC,CAAC;IAErC,oCAAoC;IACpC,MAAM,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAE1C,oCAAoC;IACpC,KAAK,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAExB,qCAAqC;IACrC,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Completion.js","sourceRoot":"","sources":["../../src/api/Completion.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OnCompletion } from "@jonloucks/concurrency-ts/api/OnCompletion";
|
|
2
|
+
import { AutoClose } from "@jonloucks/contracts-ts/api/AutoClose";
|
|
3
|
+
import { RequiredType } from "@jonloucks/concurrency-ts/api/Types";
|
|
4
|
+
/**
|
|
5
|
+
* Responsibility: Dispatch Completion status to subscribers
|
|
6
|
+
*/
|
|
7
|
+
export interface CompletionNotify<T> {
|
|
8
|
+
/**
|
|
9
|
+
* Open a notification subscription for receive completions
|
|
10
|
+
*
|
|
11
|
+
* @param onCompletion the completion
|
|
12
|
+
* @return the
|
|
13
|
+
*/
|
|
14
|
+
notify(onCompletion: OnCompletion<T>): AutoClose;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Determine if an instance implements CompletionNotify
|
|
18
|
+
*
|
|
19
|
+
* @param instance the instance to check
|
|
20
|
+
* @returns true if the instance implements CompletionNotify
|
|
21
|
+
*/
|
|
22
|
+
export declare function guard<T>(instance: unknown): instance is RequiredType<CompletionNotify<T>>;
|
|
23
|
+
//# sourceMappingURL=CompletionNotify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompletionNotify.d.ts","sourceRoot":"","sources":["../../src/api/CompletionNotify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAClE,OAAO,EAAkB,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAEnF;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAEjC;;;;;OAKG;IACH,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;CAClD;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAIzF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { guardFunctions } from "@jonloucks/concurrency-ts/api/Types";
|
|
2
|
+
/**
|
|
3
|
+
* Determine if an instance implements CompletionNotify
|
|
4
|
+
*
|
|
5
|
+
* @param instance the instance to check
|
|
6
|
+
* @returns true if the instance implements CompletionNotify
|
|
7
|
+
*/
|
|
8
|
+
export function guard(instance) {
|
|
9
|
+
return guardFunctions(instance, 'notify');
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=CompletionNotify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompletionNotify.js","sourceRoot":"","sources":["../../src/api/CompletionNotify.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAgB,MAAM,qCAAqC,CAAC;AAgBnF;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAI,QAAiB;IACxC,OAAO,cAAc,CAAC,QAAQ,EAC5B,QAAQ,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Rule } from "@jonloucks/concurrency-ts/api/Rule";
|
|
2
|
+
import { Config } from "@jonloucks/concurrency-ts/api/StateMachine";
|
|
3
|
+
/**
|
|
4
|
+
* The possible states of a Completion
|
|
5
|
+
*/
|
|
6
|
+
export declare const STATES: string[];
|
|
7
|
+
/**
|
|
8
|
+
* The possible states of a Completion
|
|
9
|
+
*/
|
|
10
|
+
export type State = typeof STATES[number];
|
|
11
|
+
/** The CompletionState type */
|
|
12
|
+
export { type State as CompletionState };
|
|
13
|
+
/** The starting state for a Completion */
|
|
14
|
+
export declare const START_STATE: State;
|
|
15
|
+
/**
|
|
16
|
+
* Get the state transition rules for a given Completion state
|
|
17
|
+
*
|
|
18
|
+
* @param state the state to get rules for
|
|
19
|
+
* @return the array of rules for the given state
|
|
20
|
+
*/
|
|
21
|
+
export declare function getStateRules(state: State): Array<Rule<State>>;
|
|
22
|
+
/**
|
|
23
|
+
* Get the default StateMachine configuration for a Completion
|
|
24
|
+
*
|
|
25
|
+
* @return the default StateMachine configuration
|
|
26
|
+
*/
|
|
27
|
+
export declare function getStateMachineConfig(): Config<State>;
|
|
28
|
+
/**
|
|
29
|
+
* Determine if a state is a terminal state
|
|
30
|
+
*
|
|
31
|
+
* @param state the state to check
|
|
32
|
+
* @return true if terminal state
|
|
33
|
+
*/
|
|
34
|
+
export declare function isTerminalState(state: State): boolean;
|
|
35
|
+
//# sourceMappingURL=CompletionState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompletionState.d.ts","sourceRoot":"","sources":["../../src/api/CompletionState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,4CAA4C,CAAC;AAGpE;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,MAAM,EAA6D,CAAC;AAEzF;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AAE1C,+BAA+B;AAC/B,OAAO,EAAE,KAAK,KAAK,IAAI,eAAe,EAAE,CAAC;AAEzC,0CAA0C;AAC1C,eAAO,MAAM,WAAW,EAAE,KAAiB,CAAC;AAE5C;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CA2B9D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,KAAK,CAAC,CAMrD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAErD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { used } from "@jonloucks/concurrency-ts/auxiliary/Checks";
|
|
2
|
+
/**
|
|
3
|
+
* The possible states of a Completion
|
|
4
|
+
*/
|
|
5
|
+
export const STATES = ['PENDING', 'FAILED', 'CANCELLED', 'SUCCEEDED'];
|
|
6
|
+
/** The starting state for a Completion */
|
|
7
|
+
export const START_STATE = 'PENDING';
|
|
8
|
+
/**
|
|
9
|
+
* Get the state transition rules for a given Completion state
|
|
10
|
+
*
|
|
11
|
+
* @param state the state to get rules for
|
|
12
|
+
* @return the array of rules for the given state
|
|
13
|
+
*/
|
|
14
|
+
export function getStateRules(state) {
|
|
15
|
+
switch (state) {
|
|
16
|
+
case 'PENDING':
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
canTransition: (event, goal) => {
|
|
20
|
+
used(event);
|
|
21
|
+
return goal === 'FAILED' || goal === 'CANCELLED' || goal === 'SUCCEEDED';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
];
|
|
25
|
+
case 'FAILED':
|
|
26
|
+
case 'CANCELLED':
|
|
27
|
+
case 'SUCCEEDED':
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
canTransition: (event, goal) => {
|
|
31
|
+
used(event);
|
|
32
|
+
used(goal);
|
|
33
|
+
return false;
|
|
34
|
+
},
|
|
35
|
+
isTerminal: true
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
default:
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
;
|
|
43
|
+
/**
|
|
44
|
+
* Get the default StateMachine configuration for a Completion
|
|
45
|
+
*
|
|
46
|
+
* @return the default StateMachine configuration
|
|
47
|
+
*/
|
|
48
|
+
export function getStateMachineConfig() {
|
|
49
|
+
return {
|
|
50
|
+
initialValue: START_STATE,
|
|
51
|
+
states: STATES,
|
|
52
|
+
getStateRules: getStateRules
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Determine if a state is a terminal state
|
|
57
|
+
*
|
|
58
|
+
* @param state the state to check
|
|
59
|
+
* @return true if terminal state
|
|
60
|
+
*/
|
|
61
|
+
export function isTerminalState(state) {
|
|
62
|
+
return state === 'FAILED' || state === 'CANCELLED' || state === 'SUCCEEDED';
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=CompletionState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompletionState.js","sourceRoot":"","sources":["../../src/api/CompletionState.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,4CAA4C,CAAC;AAElE;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAa,CAAC,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,CAAU,CAAC;AAUzF,0CAA0C;AAC1C,MAAM,CAAC,MAAM,WAAW,GAAU,SAAS,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAY;IACxC,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,SAAS;YACZ,OAAO;gBACL;oBACE,aAAa,EAAE,CAAC,KAAa,EAAE,IAAW,EAAW,EAAE;wBACrD,IAAI,CAAC,KAAK,CAAC,CAAC;wBACZ,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,WAAW,CAAC;oBAC3E,CAAC;iBACF;aACF,CAAC;QACJ,KAAK,QAAQ,CAAC;QACd,KAAK,WAAW,CAAC;QACjB,KAAK,WAAW;YACd,OAAO;gBACL;oBACE,aAAa,EAAE,CAAC,KAAa,EAAE,IAAW,EAAW,EAAE;wBACrD,IAAI,CAAC,KAAK,CAAC,CAAC;wBACZ,IAAI,CAAC,IAAI,CAAC,CAAC;wBACX,OAAO,KAAK,CAAC;oBACf,CAAC;oBACD,UAAU,EAAE,IAAI;iBACjB;aACF,CAAC;QACJ;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC;AAAA,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO;QACL,YAAY,EAAE,WAAW;QACzB,MAAM,EAAE,MAAM;QACd,aAAa,EAAE,aAAa;KAC7B,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAY;IAC1C,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Completable, Config as CompletableConfig } from "@jonloucks/concurrency-ts/api/Completable";
|
|
2
|
+
import { Completion } from "@jonloucks/concurrency-ts/api/Completion";
|
|
3
|
+
import { OnCompletion } from "@jonloucks/concurrency-ts/api/OnCompletion";
|
|
4
|
+
import { StateMachine, Config as StateMachineConfig } from "@jonloucks/concurrency-ts/api/StateMachine";
|
|
5
|
+
import { Consumer, ConsumerType, OptionalType, RequiredType, Supplier, SupplierType } from "@jonloucks/concurrency-ts/api/Types";
|
|
6
|
+
import { Waitable, Config as WaitableConfig } from "@jonloucks/concurrency-ts/api/Waitable";
|
|
7
|
+
import { Open } from "@jonloucks/contracts-ts/api/Open";
|
|
8
|
+
import { Contract, Contracts } from "@jonloucks/contracts-ts";
|
|
9
|
+
export type { Completable, CompletableConfig, Completion, StateMachine, StateMachineConfig, Waitable, WaitableConfig, OnCompletion, Consumer, ConsumerType, Supplier, SupplierType, Contracts };
|
|
10
|
+
/**
|
|
11
|
+
* The configuration used to create a new Concurrency instance.
|
|
12
|
+
*/
|
|
13
|
+
export interface Config {
|
|
14
|
+
/**
|
|
15
|
+
* @return the contracts, some use case have their own Contracts instance.
|
|
16
|
+
*/
|
|
17
|
+
contracts?: Contracts;
|
|
18
|
+
/**
|
|
19
|
+
* an optional list of events that when fired will shutdown Contracts
|
|
20
|
+
* the default is no events.
|
|
21
|
+
* It can be a custom event or system events like 'beforeExit', 'SIGINT', 'SIGTERM'
|
|
22
|
+
* @return list of shutdown event names
|
|
23
|
+
*/
|
|
24
|
+
shutdownEvents?: string[];
|
|
25
|
+
}
|
|
26
|
+
export { type Config as ConcurrencyConfig };
|
|
27
|
+
/**
|
|
28
|
+
* The Concurrency API
|
|
29
|
+
*/
|
|
30
|
+
export interface Concurrency extends Open {
|
|
31
|
+
/**
|
|
32
|
+
* Create a new Waitable with the given configuration
|
|
33
|
+
*
|
|
34
|
+
* @param config the waitable configuration
|
|
35
|
+
* @return the waitable
|
|
36
|
+
* @param <T> the type of waitable
|
|
37
|
+
*/
|
|
38
|
+
createWaitable<T>(config: WaitableConfig<T>): RequiredType<Waitable<T>>;
|
|
39
|
+
/**
|
|
40
|
+
* Create a new StateMachine
|
|
41
|
+
*
|
|
42
|
+
* @param config the state machine configuration
|
|
43
|
+
* @return the new StateMachine
|
|
44
|
+
* @param <T> the type of each state
|
|
45
|
+
* @throws IllegalArgumentException if initialState is null
|
|
46
|
+
*/
|
|
47
|
+
createStateMachine<T>(config: StateMachineConfig<T>): RequiredType<StateMachine<T>>;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new Completable
|
|
50
|
+
*
|
|
51
|
+
* @param config the completable configuration
|
|
52
|
+
* @return the new Completable
|
|
53
|
+
* @param <T> the type of completion value
|
|
54
|
+
*/
|
|
55
|
+
createCompletable<T>(config: CompletableConfig<T>): RequiredType<Completable<T>>;
|
|
56
|
+
/**
|
|
57
|
+
* Guaranteed execution: complete later block.
|
|
58
|
+
* Either the delegate successfully takes ownership of the OnCompletion or
|
|
59
|
+
* a final FAILED completion is dispatched
|
|
60
|
+
*
|
|
61
|
+
* @param onCompletion the OnCompletion callback
|
|
62
|
+
* @param delegate the intended delegate to receive the OnCompletion
|
|
63
|
+
* @param <T> the completion value type
|
|
64
|
+
*/
|
|
65
|
+
completeLater<T>(onCompletion: RequiredType<OnCompletion<T>>, delegate: RequiredType<ConsumerType<OnCompletion<T>>>): void;
|
|
66
|
+
/**
|
|
67
|
+
* Guaranteed execution: complete now block
|
|
68
|
+
* When this method finishes, it is guaranteed the OnCompletion will have received a final completion.
|
|
69
|
+
* Exceptions will result in a FAILED completion
|
|
70
|
+
* Exceptions will be rethrown.
|
|
71
|
+
*
|
|
72
|
+
* @param onCompletion the OnCompletion callback
|
|
73
|
+
* @param successBlock executed to determine the final completion value for an activity
|
|
74
|
+
* @return the final completion value
|
|
75
|
+
* @param <T> the completion value type
|
|
76
|
+
*/
|
|
77
|
+
completeNow<T>(onCompletion: RequiredType<OnCompletion<T>>, successBlock: RequiredType<SupplierType<T>>): OptionalType<T>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Determine if the given instance is a Concurrency
|
|
81
|
+
*
|
|
82
|
+
* @param instance the instance to test
|
|
83
|
+
* @return true if the instance is a Concurrency
|
|
84
|
+
*/
|
|
85
|
+
export declare function guard(instance: unknown): instance is RequiredType<Concurrency>;
|
|
86
|
+
/**
|
|
87
|
+
* The Concurrency contract
|
|
88
|
+
*/
|
|
89
|
+
export declare const CONTRACT: Contract<Concurrency>;
|
|
90
|
+
//# sourceMappingURL=Concurrency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Concurrency.d.ts","sourceRoot":"","sources":["../../src/api/Concurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AACxG,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAkB,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACjJ,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAC5F,OAAO,EAAE,IAAI,EAAE,MAAM,kCAAkC,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAkB,MAAM,yBAAyB,CAAC;AAE9E,YAAY,EACV,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,SAAS,EACV,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IAEpB;;;;;KAKC;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,OAAO,EAAE,KAAK,MAAM,IAAI,iBAAiB,EAAE,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,IAAI;IAEvC;;;;;;OAMG;IACH,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAExE;;;;;;;OAOG;IACH,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpF;;;;;;OAMG;IACH,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAEjF;;;;;;;;OAQG;IACH,aAAa,CAAC,CAAC,EAAE,YAAY,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAE3H;;;;;;;;;;OAUG;IACH,WAAW,CAAC,CAAC,EAAE,YAAY,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;CAC3H;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC,WAAW,CAAC,CAS9E;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAGzC,CAAC"}
|