@resonatehq/sdk 0.3.7 → 0.5.1
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 +24 -130
- package/dist/async.d.ts +99 -49
- package/dist/async.d.ts.map +1 -1
- package/dist/async.js +173 -100
- package/dist/async.js.map +1 -1
- package/dist/core/execution.d.ts +13 -10
- package/dist/core/execution.d.ts.map +1 -1
- package/dist/core/execution.js +174 -69
- package/dist/core/execution.js.map +1 -1
- package/dist/core/future.d.ts +6 -4
- package/dist/core/future.d.ts.map +1 -1
- package/dist/core/future.js +7 -1
- package/dist/core/future.js.map +1 -1
- package/dist/core/invocation.d.ts +6 -5
- package/dist/core/invocation.d.ts.map +1 -1
- package/dist/core/invocation.js +40 -14
- package/dist/core/invocation.js.map +1 -1
- package/dist/core/options.d.ts +32 -11
- package/dist/core/options.d.ts.map +1 -1
- package/dist/core/options.js +3 -3
- package/dist/core/options.js.map +1 -1
- package/dist/core/promises/promises.d.ts +4 -3
- package/dist/core/promises/promises.d.ts.map +1 -1
- package/dist/core/promises/promises.js +7 -3
- package/dist/core/promises/promises.js.map +1 -1
- package/dist/core/promises/types.d.ts.map +1 -1
- package/dist/core/promises/types.js +2 -5
- package/dist/core/promises/types.js.map +1 -1
- package/dist/core/schedules/schedules.d.ts +22 -0
- package/dist/core/schedules/schedules.d.ts.map +1 -0
- package/dist/core/schedules/schedules.js +29 -0
- package/dist/core/schedules/schedules.js.map +1 -0
- package/dist/core/store.d.ts +5 -2
- package/dist/core/store.d.ts.map +1 -1
- package/dist/core/stores/local.d.ts +1 -1
- package/dist/core/stores/local.d.ts.map +1 -1
- package/dist/core/stores/local.js +7 -5
- package/dist/core/stores/local.js.map +1 -1
- package/dist/core/stores/remote.d.ts +7 -7
- package/dist/core/stores/remote.d.ts.map +1 -1
- package/dist/core/stores/remote.js +30 -23
- package/dist/core/stores/remote.js.map +1 -1
- package/dist/generator.d.ts +39 -18
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +72 -73
- package/dist/generator.js.map +1 -1
- package/dist/index.d.ts +23 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -6
- package/dist/index.js.map +1 -1
- package/dist/resonate.d.ts +109 -32
- package/dist/resonate.d.ts.map +1 -1
- package/dist/resonate.js +144 -60
- package/dist/resonate.js.map +1 -1
- package/package.json +1 -1
package/dist/async.js
CHANGED
|
@@ -1,33 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Context = exports.
|
|
3
|
+
exports.Context = exports.Resonate = void 0;
|
|
27
4
|
const execution_1 = require("./core/execution");
|
|
28
5
|
const invocation_1 = require("./core/invocation");
|
|
29
6
|
const retry_1 = require("./core/retries/retry");
|
|
30
|
-
const utils = __importStar(require("./core/utils"));
|
|
31
7
|
const resonate_1 = require("./resonate");
|
|
32
8
|
/////////////////////////////////////////////////////////////////////
|
|
33
9
|
// Resonate
|
|
@@ -42,10 +18,22 @@ class Resonate extends resonate_1.ResonateBase {
|
|
|
42
18
|
*/
|
|
43
19
|
constructor(opts = {}) {
|
|
44
20
|
super(opts);
|
|
45
|
-
this.scheduler = new Scheduler();
|
|
21
|
+
this.scheduler = new Scheduler(this);
|
|
46
22
|
}
|
|
47
|
-
|
|
48
|
-
return
|
|
23
|
+
execute(name, id, func, args, opts, defaults, durablePromise) {
|
|
24
|
+
return this.scheduler.add(name, id, func, args, opts, defaults, durablePromise);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Register a function with Resonate. Registered functions can be invoked by calling {@link run}, or by the returned function.
|
|
28
|
+
*
|
|
29
|
+
* @template F The type of the function.
|
|
30
|
+
* @param name A unique name to identify the function.
|
|
31
|
+
* @param func The function to register with Resonate.
|
|
32
|
+
* @param opts Resonate options, can be constructed by calling {@link options}.
|
|
33
|
+
* @returns Resonate function
|
|
34
|
+
*/
|
|
35
|
+
register(name, func, opts) {
|
|
36
|
+
return super.register(name, func, opts);
|
|
49
37
|
}
|
|
50
38
|
/**
|
|
51
39
|
* Register a module with Resonate. Registered functions can be invoked by calling {@link run}.
|
|
@@ -58,17 +46,19 @@ class Resonate extends resonate_1.ResonateBase {
|
|
|
58
46
|
registerModule(module, opts = {}) {
|
|
59
47
|
super.registerModule(module, opts);
|
|
60
48
|
}
|
|
61
|
-
|
|
62
|
-
return
|
|
49
|
+
schedule(name, cron, func, ...args) {
|
|
50
|
+
return super.schedule(name, cron, func, ...args);
|
|
63
51
|
}
|
|
64
52
|
}
|
|
65
53
|
exports.Resonate = Resonate;
|
|
66
54
|
/////////////////////////////////////////////////////////////////////
|
|
67
55
|
// Context
|
|
68
56
|
/////////////////////////////////////////////////////////////////////
|
|
69
|
-
class
|
|
57
|
+
class Context {
|
|
58
|
+
resonate;
|
|
70
59
|
invocation;
|
|
71
|
-
constructor(invocation) {
|
|
60
|
+
constructor(resonate, invocation) {
|
|
61
|
+
this.resonate = resonate;
|
|
72
62
|
this.invocation = invocation;
|
|
73
63
|
}
|
|
74
64
|
/**
|
|
@@ -77,43 +67,18 @@ class Info {
|
|
|
77
67
|
get attempt() {
|
|
78
68
|
return this.invocation.attempt;
|
|
79
69
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Uniquely identifies the function invocation.
|
|
82
|
-
*/
|
|
83
|
-
get id() {
|
|
84
|
-
return this.invocation.id;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Deduplicates function invocations with the same id.
|
|
88
|
-
*/
|
|
89
|
-
get idempotencyKey() {
|
|
90
|
-
return this.invocation.idempotencyKey;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* The timestamp in ms, once this time elapses the function invocation will timeout.
|
|
94
|
-
*/
|
|
95
|
-
get timeout() {
|
|
96
|
-
return this.invocation.timeout;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* The resonate function version.
|
|
100
|
-
*/
|
|
101
|
-
get version() {
|
|
102
|
-
return this.invocation.version;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.Info = Info;
|
|
106
|
-
class Context {
|
|
107
|
-
invocation;
|
|
108
|
-
constructor(invocation) {
|
|
109
|
-
this.invocation = invocation;
|
|
110
|
-
}
|
|
111
70
|
/**
|
|
112
71
|
* The running count of child function invocations.
|
|
113
72
|
*/
|
|
114
73
|
get counter() {
|
|
115
74
|
return this.invocation.counter;
|
|
116
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The time the invocation was created. Will use the durable promise creation time if available.
|
|
78
|
+
*/
|
|
79
|
+
get createdOn() {
|
|
80
|
+
return this.invocation.createdOn;
|
|
81
|
+
}
|
|
117
82
|
/**
|
|
118
83
|
* Uniquely identifies the function invocation.
|
|
119
84
|
*/
|
|
@@ -126,6 +91,12 @@ class Context {
|
|
|
126
91
|
get idempotencyKey() {
|
|
127
92
|
return this.invocation.idempotencyKey;
|
|
128
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* All configured options for this context.
|
|
96
|
+
*/
|
|
97
|
+
get opts() {
|
|
98
|
+
return this.invocation.opts;
|
|
99
|
+
}
|
|
129
100
|
/**
|
|
130
101
|
* The timestamp in ms, once this time elapses the function invocation will timeout.
|
|
131
102
|
*/
|
|
@@ -136,7 +107,7 @@ class Context {
|
|
|
136
107
|
* The resonate function version.
|
|
137
108
|
*/
|
|
138
109
|
get version() {
|
|
139
|
-
return this.invocation.version;
|
|
110
|
+
return this.invocation.root.opts.version;
|
|
140
111
|
}
|
|
141
112
|
run(func, ...argsWithOpts) {
|
|
142
113
|
// the parent is the current invocation
|
|
@@ -147,59 +118,159 @@ class Context {
|
|
|
147
118
|
const id = typeof func === "string" ? func : `${parent.id}.${parent.counter}`;
|
|
148
119
|
// human readable name of the function
|
|
149
120
|
const name = typeof func === "string" ? func : func.name;
|
|
150
|
-
// version is inherited from the parent
|
|
151
|
-
const version = parent.version;
|
|
152
|
-
// the idempotency key is a hash of the id
|
|
153
|
-
const idempotencyKey = utils.hash(id);
|
|
154
121
|
// opts are optional and can be provided as the last arg
|
|
155
122
|
const { args, opts } = this.invocation.split(argsWithOpts);
|
|
123
|
+
// default opts never change
|
|
124
|
+
const defaults = this.invocation.defaults;
|
|
156
125
|
// param is only required for deferred executions
|
|
157
126
|
const param = typeof func === "string" ? args[0] : undefined;
|
|
158
127
|
// create a new invocation
|
|
159
|
-
const invocation = new invocation_1.Invocation(name,
|
|
128
|
+
const invocation = new invocation_1.Invocation(name, id, undefined, param, opts, defaults, parent);
|
|
160
129
|
let execution;
|
|
161
130
|
if (typeof func === "string") {
|
|
162
131
|
// create a deferred execution
|
|
163
132
|
// this execution will be fulfilled out-of-process
|
|
164
|
-
execution = new execution_1.DeferredExecution(invocation);
|
|
133
|
+
execution = new execution_1.DeferredExecution(this.resonate, invocation);
|
|
165
134
|
}
|
|
166
135
|
else {
|
|
167
|
-
// create an ordinary execution
|
|
136
|
+
// create an ordinary execution
|
|
168
137
|
// this execution wraps a user-provided function
|
|
169
|
-
const ctx = new Context(invocation);
|
|
170
|
-
execution = new execution_1.OrdinaryExecution(invocation, () => func(ctx, ...args)
|
|
138
|
+
const ctx = new Context(this.resonate, invocation);
|
|
139
|
+
execution = new execution_1.OrdinaryExecution(this.resonate, invocation, () => func(ctx, ...args));
|
|
171
140
|
}
|
|
172
141
|
// bump the counter
|
|
173
142
|
parent.counter++;
|
|
174
143
|
// return a resonate promise
|
|
175
144
|
return execution.execute();
|
|
176
145
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
//
|
|
187
|
-
//
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Creates a Promise that is resolved with an array of results when all of the provided Promises
|
|
148
|
+
* resolve, or rejected when any Promise is rejected.
|
|
149
|
+
*
|
|
150
|
+
* @param values An array of Promises.
|
|
151
|
+
* @param opts Optional {@link options}.
|
|
152
|
+
* @returns A new ResonatePromise.
|
|
153
|
+
*/
|
|
154
|
+
all(values, opts = {}) {
|
|
155
|
+
// catch all promises to prevent unhandled promise rejections,
|
|
156
|
+
// since Promise.all will not be called in the case where the
|
|
157
|
+
// durable promise already completed
|
|
158
|
+
for (const value of values) {
|
|
159
|
+
if (value instanceof Promise) {
|
|
160
|
+
value.catch(() => { });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// prettier-ignore
|
|
164
|
+
return this.run(() => Promise.all(values), this.options({
|
|
165
|
+
retry: retry_1.Retry.never(),
|
|
166
|
+
...opts,
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Creates a Promise that is fulfilled by the first given promise to be fulfilled, or rejected
|
|
171
|
+
* with an AggregateError.
|
|
172
|
+
*
|
|
173
|
+
* @param values An array of Promises.
|
|
174
|
+
* @param opts Optional {@link options}.
|
|
175
|
+
* @returns A new ResonatePromise.
|
|
176
|
+
*/
|
|
177
|
+
any(values, opts = {}) {
|
|
178
|
+
// catch all promises to prevent unhandled promise rejections,
|
|
179
|
+
// since Promise.any will not be called in the case where the
|
|
180
|
+
// durable promise already completed
|
|
181
|
+
for (const value of values) {
|
|
182
|
+
if (value instanceof Promise) {
|
|
183
|
+
value.catch(() => { });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// prettier-ignore
|
|
187
|
+
return this.run(() => Promise.any(values), this.options({
|
|
188
|
+
retry: retry_1.Retry.never(),
|
|
189
|
+
...opts,
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
|
|
194
|
+
* or rejected.
|
|
195
|
+
*
|
|
196
|
+
* @param values An array of Promises.
|
|
197
|
+
* @param opts Optional {@link options}.
|
|
198
|
+
* @returns A new ResonatePromise.
|
|
199
|
+
*/
|
|
200
|
+
race(values, opts = {}) {
|
|
201
|
+
// catch all promises to prevent unhandled promise rejections,
|
|
202
|
+
// since Promise.race will not be called in the case where the
|
|
203
|
+
// durable promise already completed
|
|
204
|
+
for (const value of values) {
|
|
205
|
+
if (value instanceof Promise) {
|
|
206
|
+
value.catch(() => { });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// prettier-ignore
|
|
210
|
+
return this.run(() => Promise.race(values), this.options({
|
|
211
|
+
retry: retry_1.Retry.never(),
|
|
212
|
+
...opts,
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Creates a Promise that is resolved with an array of results when all of the provided Promises
|
|
217
|
+
* resolve or reject.
|
|
218
|
+
*
|
|
219
|
+
* @param values An array of Promises.
|
|
220
|
+
* @param opts Optional {@link options}.
|
|
221
|
+
* @returns A new ResonatePromise.
|
|
222
|
+
*/
|
|
223
|
+
allSettled(values, opts = {}) {
|
|
224
|
+
// catch all promises to prevent unhandled promise rejections,
|
|
225
|
+
// since Promise.allSettled will not be called in the case where the
|
|
226
|
+
// durable promise already completed
|
|
227
|
+
for (const value of values) {
|
|
228
|
+
if (value instanceof Promise) {
|
|
229
|
+
value.catch(() => { });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// prettier-ignore
|
|
233
|
+
return this.run(() => Promise.allSettled(values), this.options({
|
|
234
|
+
retry: retry_1.Retry.never(),
|
|
235
|
+
...opts,
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Generate a deterministic random number.
|
|
240
|
+
*
|
|
241
|
+
* @returns A random number.
|
|
242
|
+
*/
|
|
243
|
+
random() {
|
|
244
|
+
return this.run(Math.random);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Get a deterministic timestamp.
|
|
248
|
+
*
|
|
249
|
+
* @returns A timestamp in ms.
|
|
250
|
+
*/
|
|
251
|
+
now() {
|
|
252
|
+
return this.run(Date.now);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Run a Resonate function in detached mode. Functions must first be registered with Resonate.
|
|
256
|
+
*
|
|
257
|
+
* @template T The return type of the function.
|
|
258
|
+
* @param id A unique id for the function invocation.
|
|
259
|
+
* @param name The function name.
|
|
260
|
+
* @param args The function arguments.
|
|
261
|
+
* @returns A ResonatePromise.
|
|
262
|
+
*/
|
|
263
|
+
detached(name, id, ...args) {
|
|
264
|
+
return this.resonate.run(name, id, ...args);
|
|
194
265
|
}
|
|
195
266
|
/**
|
|
196
267
|
* Construct options.
|
|
197
268
|
*
|
|
198
269
|
* @param opts A partial {@link Options} object.
|
|
199
|
-
* @returns
|
|
270
|
+
* @returns PartialOptions.
|
|
200
271
|
*/
|
|
201
272
|
options(opts = {}) {
|
|
202
|
-
return
|
|
273
|
+
return this.resonate.options(opts);
|
|
203
274
|
}
|
|
204
275
|
}
|
|
205
276
|
exports.Context = Context;
|
|
@@ -207,27 +278,29 @@ exports.Context = Context;
|
|
|
207
278
|
// Scheduler
|
|
208
279
|
/////////////////////////////////////////////////////////////////////
|
|
209
280
|
class Scheduler {
|
|
281
|
+
resonate;
|
|
210
282
|
cache = {};
|
|
211
|
-
|
|
283
|
+
constructor(resonate) {
|
|
284
|
+
this.resonate = resonate;
|
|
285
|
+
}
|
|
286
|
+
add(name, id, func, args, opts, defaults, durablePromise) {
|
|
212
287
|
// if the execution is already running, and not killed,
|
|
213
288
|
// return the promise
|
|
214
|
-
if (this.cache[id] && !this.cache[id].killed) {
|
|
289
|
+
if (opts.durable && this.cache[id] && !this.cache[id].killed) {
|
|
215
290
|
// execute is idempotent
|
|
216
291
|
return this.cache[id].execute();
|
|
217
292
|
}
|
|
218
|
-
// the idempotency key is a hash of the id
|
|
219
|
-
const idempotencyKey = utils.hash(id);
|
|
220
293
|
// params, used for recovery
|
|
221
294
|
const param = {
|
|
222
295
|
func: name,
|
|
223
|
-
version,
|
|
296
|
+
version: opts.version,
|
|
224
297
|
args,
|
|
225
298
|
};
|
|
226
299
|
// create a new invocation
|
|
227
|
-
const invocation = new invocation_1.Invocation(name,
|
|
300
|
+
const invocation = new invocation_1.Invocation(name, id, undefined, param, opts, defaults);
|
|
228
301
|
// create a new execution
|
|
229
|
-
const ctx = new Context(invocation);
|
|
230
|
-
const execution = new execution_1.OrdinaryExecution(invocation, () => func(ctx, ...args));
|
|
302
|
+
const ctx = new Context(this.resonate, invocation);
|
|
303
|
+
const execution = new execution_1.OrdinaryExecution(this.resonate, invocation, () => func(ctx, ...args), durablePromise);
|
|
231
304
|
// store the execution,
|
|
232
305
|
// will be used if run is called again with the same id
|
|
233
306
|
this.cache[id] = execution;
|
package/dist/async.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async.js","sourceRoot":"","sources":["../lib/async.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"async.js","sourceRoot":"","sources":["../lib/async.ts"],"names":[],"mappings":";;;AAAA,gDAAmF;AAEnF,kDAA+C;AAG/C,gDAA6C;AAE7C,yCAA0C;AAY1C,qEAAqE;AACrE,WAAW;AACX,qEAAqE;AAErE,MAAa,QAAS,SAAQ,uBAAY;IAChC,SAAS,CAAY;IAE7B;;;;;OAKG;IACH,YAAY,OAAiC,EAAE;QAC7C,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAES,OAAO,CACf,IAAY,EACZ,EAAU,EACV,IAAO,EACP,IAAe,EACf,IAAa,EACb,QAAiB,EACjB,cAAoC;QAEpC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;IAClF,CAAC;IAED;;;;;;;;OAQG;IACH,QAAQ,CACN,IAAY,EACZ,IAAO,EACP,IAAuB;QAEvB,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;;OAOG;IACH,cAAc,CAAiB,MAAyB,EAAE,OAAyB,EAAE;QACnF,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IA4BD,QAAQ,CAAC,IAAY,EAAE,IAAY,EAAE,IAAmB,EAAE,GAAG,IAAW;QACtE,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;IACnD,CAAC;CACF;AApFD,4BAoFC;AAED,qEAAq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AE,CAAC,GAAG,SAAS,CAAC;QAE3B,OAAO,SAAS,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
package/dist/core/execution.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { ResonateBase } from "../resonate";
|
|
1
2
|
import { Future, ResonatePromise } from "./future";
|
|
2
3
|
import { Invocation } from "./invocation";
|
|
3
4
|
import { DurablePromise } from "./promises/promises";
|
|
4
|
-
import { IRetry } from "./retry";
|
|
5
5
|
export declare abstract class Execution<T> {
|
|
6
|
+
resonate: ResonateBase;
|
|
6
7
|
invocation: Invocation<T>;
|
|
7
8
|
private promise;
|
|
8
9
|
/**
|
|
@@ -11,33 +12,35 @@ export declare abstract class Execution<T> {
|
|
|
11
12
|
* @constructor
|
|
12
13
|
* @param invocation - An invocation correpsonding to the Resonate function.
|
|
13
14
|
*/
|
|
14
|
-
constructor(invocation: Invocation<T>);
|
|
15
|
+
constructor(resonate: ResonateBase, invocation: Invocation<T>);
|
|
15
16
|
execute(): ResonatePromise<T>;
|
|
16
17
|
protected abstract fork(): Promise<Future<T>>;
|
|
17
18
|
protected abstract join(future: Future<T>): Promise<T>;
|
|
18
19
|
get killed(): boolean;
|
|
19
20
|
kill(error: unknown): void;
|
|
20
|
-
protected
|
|
21
|
+
protected acquireLock(): Promise<boolean>;
|
|
22
|
+
protected releaseLock(): Promise<void>;
|
|
21
23
|
}
|
|
22
24
|
export declare class OrdinaryExecution<T> extends Execution<T> {
|
|
23
25
|
private func;
|
|
24
|
-
private
|
|
25
|
-
constructor(invocation: Invocation<T>, func: () => T,
|
|
26
|
+
private durablePromise?;
|
|
27
|
+
constructor(resonate: ResonateBase, invocation: Invocation<T>, func: () => T, durablePromise?: DurablePromise<T> | undefined);
|
|
26
28
|
protected fork(): Promise<Future<T>>;
|
|
27
29
|
protected join(future: Future<T>): Promise<T>;
|
|
28
30
|
private run;
|
|
29
31
|
}
|
|
30
32
|
export declare class DeferredExecution<T> extends Execution<T> {
|
|
31
|
-
|
|
33
|
+
private durablePromise;
|
|
32
34
|
protected fork(): Promise<Future<T>>;
|
|
33
35
|
protected join(future: Future<T>): Promise<T>;
|
|
34
36
|
}
|
|
35
37
|
export declare class GeneratorExecution<T> extends Execution<T> {
|
|
36
38
|
generator: Generator<any, T>;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
private durablePromise?;
|
|
40
|
+
constructor(resonate: ResonateBase, invocation: Invocation<T>, generator: Generator<any, T>, durablePromise?: DurablePromise<T> | undefined);
|
|
41
|
+
create(): Promise<void>;
|
|
42
|
+
resolve(value: T): Promise<void>;
|
|
43
|
+
reject(error: any): Promise<void>;
|
|
41
44
|
protected fork(): Promise<Future<T>>;
|
|
42
45
|
protected join(future: Future<T>): Promise<T>;
|
|
43
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../lib/core/execution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../lib/core/execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAMrD,8BAAsB,SAAS,CAAC,CAAC;IAUtB,QAAQ,EAAE,YAAY;IACtB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IAVlC,OAAO,CAAC,OAAO,CAAmC;IAElD;;;;;OAKG;gBAEM,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IAGlC,OAAO,IAAI,eAAe,CAAC,CAAC,CAAC;IAoB7B,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,M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