exupery-core-internals 0.1.5 → 0.1.7
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/dist/imp/public/array_literal.js +0 -50
- package/dist/imp/public/dictionary_literal.js +0 -50
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/package.json +2 -2
- package/dist/imp/private/create_asynchronous_processes_monitor.d.ts +0 -15
- package/dist/imp/private/create_asynchronous_processes_monitor.js +0 -52
- package/dist/imp/public/create_Async_Value.d.ts +0 -10
- package/dist/imp/public/create_Async_Value.js +0 -37
- package/dist/imp/public/create_Unsafe_Async_Value.d.ts +0 -17
- package/dist/imp/public/create_Unsafe_Async_Value.js +0 -76
- package/dist/imp/public/make_async.d.ts +0 -7
- package/dist/imp/public/make_async.js +0 -16
- package/dist/imp/public/resolve_async_tuple_2.d.ts +0 -6
- package/dist/imp/public/resolve_async_tuple_2.js +0 -29
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.array_literal = array_literal;
|
|
4
|
-
const create_asynchronous_processes_monitor_1 = require("../private/create_asynchronous_processes_monitor");
|
|
5
|
-
const create_Async_Value_1 = require("./create_Async_Value");
|
|
6
|
-
const create_Unsafe_Async_Value_1 = require("./create_Unsafe_Async_Value");
|
|
7
4
|
const not_set_1 = require("./not_set");
|
|
8
5
|
const set_1 = require("./set");
|
|
9
6
|
/**
|
|
@@ -20,53 +17,6 @@ class Array_Class {
|
|
|
20
17
|
return $v(entry);
|
|
21
18
|
}));
|
|
22
19
|
}
|
|
23
|
-
map_async(on_element_value) {
|
|
24
|
-
const data = this.data;
|
|
25
|
-
return (0, create_Async_Value_1.create_Async_Value)({
|
|
26
|
-
'execute': (on_array_value) => {
|
|
27
|
-
const temp = [];
|
|
28
|
-
(0, create_asynchronous_processes_monitor_1.create_asynchronous_processes_monitor)((registry) => {
|
|
29
|
-
data.map(on_element_value).forEach((v) => {
|
|
30
|
-
registry['report process started']();
|
|
31
|
-
v.__start((v) => {
|
|
32
|
-
temp.push(v);
|
|
33
|
-
registry['report process finished']();
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
}, () => {
|
|
37
|
-
on_array_value(array_literal(temp));
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
map_async_unsafe(on_element_value) {
|
|
43
|
-
const data = this.data;
|
|
44
|
-
return (0, create_Unsafe_Async_Value_1.create_Unsafe_Async_Value)({
|
|
45
|
-
'execute': (on_array_value, on_array_exception) => {
|
|
46
|
-
const temp_values = [];
|
|
47
|
-
const temp_exceptions = [];
|
|
48
|
-
(0, create_asynchronous_processes_monitor_1.create_asynchronous_processes_monitor)((registry) => {
|
|
49
|
-
data.map(on_element_value).forEach((v) => {
|
|
50
|
-
registry['report process started']();
|
|
51
|
-
v.__start(($) => {
|
|
52
|
-
temp_values.push($);
|
|
53
|
-
registry['report process finished']();
|
|
54
|
-
}, ($) => {
|
|
55
|
-
temp_exceptions.push($);
|
|
56
|
-
registry['report process finished']();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}, () => {
|
|
60
|
-
if (temp_exceptions.length > 0) {
|
|
61
|
-
on_array_exception(array_literal(temp_exceptions));
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
on_array_value(array_literal(temp_values));
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
20
|
//internal methods
|
|
71
21
|
__for_each($i) {
|
|
72
22
|
this.data.forEach(($) => {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dictionary_literal = dictionary_literal;
|
|
4
|
-
const create_asynchronous_processes_monitor_1 = require("../private/create_asynchronous_processes_monitor");
|
|
5
|
-
const create_Async_Value_1 = require("./create_Async_Value");
|
|
6
|
-
const create_Unsafe_Async_Value_1 = require("./create_Unsafe_Async_Value");
|
|
7
4
|
const set_1 = require("./set");
|
|
8
5
|
const not_set_1 = require("./not_set");
|
|
9
6
|
const array_literal_1 = require("./array_literal");
|
|
@@ -22,53 +19,6 @@ class Dictionary {
|
|
|
22
19
|
};
|
|
23
20
|
}));
|
|
24
21
|
}
|
|
25
|
-
map_async(on_entry_value) {
|
|
26
|
-
const source = this.source;
|
|
27
|
-
const temp = {};
|
|
28
|
-
return (0, create_Async_Value_1.create_Async_Value)({
|
|
29
|
-
'execute': (on_dictionary_value) => {
|
|
30
|
-
(0, create_asynchronous_processes_monitor_1.create_asynchronous_processes_monitor)((counter) => {
|
|
31
|
-
source.map(($) => {
|
|
32
|
-
counter['report process started']();
|
|
33
|
-
on_entry_value($.value).__start((nv) => {
|
|
34
|
-
temp[$.key] = nv;
|
|
35
|
-
counter['report process finished']();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}, () => {
|
|
39
|
-
on_dictionary_value(dictionary_literal(temp));
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
map_async_unsafe(on_entry_value) {
|
|
45
|
-
const source = this.source;
|
|
46
|
-
const temp_values = {};
|
|
47
|
-
const temp_exceptions = {};
|
|
48
|
-
return (0, create_Unsafe_Async_Value_1.create_Unsafe_Async_Value)({
|
|
49
|
-
'execute': (on_dictionary_value, on_dictionary_exception) => {
|
|
50
|
-
(0, create_asynchronous_processes_monitor_1.create_asynchronous_processes_monitor)((counter) => {
|
|
51
|
-
source.map(($) => {
|
|
52
|
-
counter['report process started']();
|
|
53
|
-
on_entry_value($.value).__start((value) => {
|
|
54
|
-
temp_values[$.key] = value;
|
|
55
|
-
counter['report process finished']();
|
|
56
|
-
}, (exception) => {
|
|
57
|
-
temp_exceptions[$.key] = exception;
|
|
58
|
-
counter['report process finished']();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
}, () => {
|
|
62
|
-
if (Object.keys(temp_exceptions).length > 0) {
|
|
63
|
-
on_dictionary_exception(dictionary_literal(temp_exceptions));
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
on_dictionary_value(dictionary_literal(temp_values));
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
22
|
__map_with_key($v) {
|
|
73
23
|
return new Dictionary(this.source.map(($) => {
|
|
74
24
|
return {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,9 +6,6 @@ export * from "./imp/public/change_context";
|
|
|
6
6
|
export * from "./imp/public/block";
|
|
7
7
|
export * from "./imp/public/switch_state";
|
|
8
8
|
export * from "./imp/public/get_location_info";
|
|
9
|
-
export * from "./imp/public/resolve_async_tuple_2";
|
|
10
|
-
export * from "./imp/public/make_async";
|
|
11
|
-
export * from "./imp/public/create_Async_Value";
|
|
12
9
|
export * from "./imp/public/set";
|
|
13
10
|
export * from "./imp/public/not_set";
|
|
14
11
|
export * from "./imp/public/Error";
|
package/dist/index.js
CHANGED
|
@@ -22,9 +22,6 @@ __exportStar(require("./imp/public/change_context"), exports);
|
|
|
22
22
|
__exportStar(require("./imp/public/block"), exports);
|
|
23
23
|
__exportStar(require("./imp/public/switch_state"), exports);
|
|
24
24
|
__exportStar(require("./imp/public/get_location_info"), exports);
|
|
25
|
-
__exportStar(require("./imp/public/resolve_async_tuple_2"), exports);
|
|
26
|
-
__exportStar(require("./imp/public/make_async"), exports);
|
|
27
|
-
__exportStar(require("./imp/public/create_Async_Value"), exports);
|
|
28
25
|
__exportStar(require("./imp/public/set"), exports);
|
|
29
26
|
__exportStar(require("./imp/public/not_set"), exports);
|
|
30
27
|
__exportStar(require("./imp/public/Error"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exupery-core-internals",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "Corno",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"url": "https://github.com/corno/exupery-core/issues"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"exupery-core-types": "^0.1.
|
|
18
|
+
"exupery-core-types": "^0.1.5"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^18.15.3"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type I_Async_Monitor = {
|
|
2
|
-
readonly 'report process started': () => void;
|
|
3
|
-
readonly 'report process finished': () => void;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* this function helps in keeping track of ongoing async operations
|
|
7
|
-
* async operations are registered and when finished reported as such.
|
|
8
|
-
* when all ongoing operations are finished the onEnd callback is called
|
|
9
|
-
*
|
|
10
|
-
* this function is specifically useful for async map functions
|
|
11
|
-
*
|
|
12
|
-
* @param callback this callback creates a scope within which the counter is provided
|
|
13
|
-
* @param onEnd this callback will be called when all ongoing operations are finished
|
|
14
|
-
*/
|
|
15
|
-
export declare function create_asynchronous_processes_monitor(monitoring_phase: ($: I_Async_Monitor) => void, on_all_finished: () => void): void;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.create_asynchronous_processes_monitor = create_asynchronous_processes_monitor;
|
|
4
|
-
/**
|
|
5
|
-
* this function helps in keeping track of ongoing async operations
|
|
6
|
-
* async operations are registered and when finished reported as such.
|
|
7
|
-
* when all ongoing operations are finished the onEnd callback is called
|
|
8
|
-
*
|
|
9
|
-
* this function is specifically useful for async map functions
|
|
10
|
-
*
|
|
11
|
-
* @param callback this callback creates a scope within which the counter is provided
|
|
12
|
-
* @param onEnd this callback will be called when all ongoing operations are finished
|
|
13
|
-
*/
|
|
14
|
-
function create_asynchronous_processes_monitor(monitoring_phase, on_all_finished) {
|
|
15
|
-
let counter = 0;
|
|
16
|
-
/*
|
|
17
|
-
* we need to keep track of if the registration phase is ended or not.
|
|
18
|
-
* it can happen that the counter reaches 0 during the registration phase, specifically if there is no real async calls being made
|
|
19
|
-
* in that case the reportFinished counter is als called during the registration phase.
|
|
20
|
-
* If that happens there should not yet be a call to onEnd().
|
|
21
|
-
*/
|
|
22
|
-
let registration_phase_ended = false;
|
|
23
|
-
let on_all_finished_has_been_called = false;
|
|
24
|
-
function checkStatus() {
|
|
25
|
-
if (registration_phase_ended) {
|
|
26
|
-
if (counter === 0) {
|
|
27
|
-
if (on_all_finished_has_been_called === true) {
|
|
28
|
-
throw new Error("CORE: already ended");
|
|
29
|
-
}
|
|
30
|
-
on_all_finished_has_been_called = true;
|
|
31
|
-
on_all_finished();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
monitoring_phase({
|
|
36
|
-
'report process started': () => {
|
|
37
|
-
if (on_all_finished_has_been_called) {
|
|
38
|
-
throw new Error("CORE: async call done after context is ready");
|
|
39
|
-
}
|
|
40
|
-
counter += 1;
|
|
41
|
-
},
|
|
42
|
-
'report process finished': () => {
|
|
43
|
-
if (counter === 0) {
|
|
44
|
-
throw new Error("CORE: decrement while counter is 0");
|
|
45
|
-
}
|
|
46
|
-
counter -= 1;
|
|
47
|
-
checkStatus();
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
registration_phase_ended = true;
|
|
51
|
-
checkStatus();
|
|
52
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as pt from "exupery-core-types";
|
|
2
|
-
export type Executer<T> = {
|
|
3
|
-
'execute': (on_value: ($: T) => void) => void;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* returns an {@link Async_Value }
|
|
7
|
-
* @param executer the function that produces the eventual value
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
export declare function create_Async_Value<T>(executer: Executer<T>): pt.Async_Value<T>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.create_Async_Value = create_Async_Value;
|
|
4
|
-
class Async_Value_Class {
|
|
5
|
-
constructor(executer) {
|
|
6
|
-
this.executer = executer;
|
|
7
|
-
}
|
|
8
|
-
map(handle_value) {
|
|
9
|
-
return create_Async_Value({
|
|
10
|
-
'execute': (on_value) => {
|
|
11
|
-
this.executer.execute((value) => {
|
|
12
|
-
on_value(handle_value(value));
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
then(handle_value) {
|
|
18
|
-
return create_Async_Value({
|
|
19
|
-
'execute': (on_value) => {
|
|
20
|
-
this.executer.execute((value) => {
|
|
21
|
-
handle_value(value).__start(on_value);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
__start(on_value) {
|
|
27
|
-
this.executer.execute(on_value);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* returns an {@link Async_Value }
|
|
32
|
-
* @param executer the function that produces the eventual value
|
|
33
|
-
* @returns
|
|
34
|
-
*/
|
|
35
|
-
function create_Async_Value(executer) {
|
|
36
|
-
return new Async_Value_Class(executer);
|
|
37
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as _et from "exupery-core-types";
|
|
2
|
-
/**
|
|
3
|
-
* this function contains the body in which the async value or exception is executed
|
|
4
|
-
* after the execution, either the on_value or on_exception callback will be called
|
|
5
|
-
* @param on_value the callback to call when a value is produced
|
|
6
|
-
* @param on_exception the callback to call when an error is produced
|
|
7
|
-
*/
|
|
8
|
-
type Executer<T, E> = {
|
|
9
|
-
'execute': (on_value: ($: T) => void, on_exception: ($: E) => void) => void;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* returns an {@link Async_Value }
|
|
13
|
-
* @param executer the function that produces the eventual value
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export declare function create_Unsafe_Async_Value<T, E>(executer: Executer<T, E>): _et.Unsafe_Async_Value<T, E>;
|
|
17
|
-
export {};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.create_Unsafe_Async_Value = create_Unsafe_Async_Value;
|
|
4
|
-
const create_Async_Value_1 = require("./create_Async_Value");
|
|
5
|
-
class Unsafe_Async_Value_Class {
|
|
6
|
-
constructor(executer) {
|
|
7
|
-
this.executer = executer;
|
|
8
|
-
}
|
|
9
|
-
map(handle_value) {
|
|
10
|
-
return new Unsafe_Async_Value_Class({
|
|
11
|
-
'execute': (on_value, on_exception) => {
|
|
12
|
-
this.executer.execute(($) => {
|
|
13
|
-
on_value(handle_value($));
|
|
14
|
-
}, on_exception);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
then(handle_value) {
|
|
19
|
-
return new Unsafe_Async_Value_Class({
|
|
20
|
-
'execute': (new_on_value, new_on_exception) => {
|
|
21
|
-
this.executer.execute(($) => {
|
|
22
|
-
handle_value($).__start(new_on_value, new_on_exception);
|
|
23
|
-
}, new_on_exception);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
if_exception_then(handle_exception) {
|
|
28
|
-
return new Unsafe_Async_Value_Class({
|
|
29
|
-
'execute': (new_on_value, new_on_exception) => {
|
|
30
|
-
this.executer.execute(new_on_value, ($) => {
|
|
31
|
-
handle_exception($).__start(new_on_value, new_on_exception);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
map_exception(handle_exception) {
|
|
37
|
-
return new Unsafe_Async_Value_Class({
|
|
38
|
-
'execute': (on_value, on_exception) => {
|
|
39
|
-
this.executer.execute(on_value, ($) => {
|
|
40
|
-
on_exception(handle_exception($));
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
catch(handle_exception) {
|
|
46
|
-
return (0, create_Async_Value_1.create_Async_Value)({
|
|
47
|
-
'execute': (on_value) => {
|
|
48
|
-
this.executer.execute(on_value, ($) => {
|
|
49
|
-
on_value(handle_exception($));
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
catch_and_map(handle_value, handle_exception) {
|
|
55
|
-
return (0, create_Async_Value_1.create_Async_Value)({
|
|
56
|
-
'execute': (on_value) => {
|
|
57
|
-
this.executer.execute(($) => {
|
|
58
|
-
on_value(handle_value($));
|
|
59
|
-
}, ($) => {
|
|
60
|
-
on_value(handle_exception($));
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
__start(on_value, on_exception) {
|
|
66
|
-
this.executer.execute(on_value, on_exception);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* returns an {@link Async_Value }
|
|
71
|
-
* @param executer the function that produces the eventual value
|
|
72
|
-
* @returns
|
|
73
|
-
*/
|
|
74
|
-
function create_Unsafe_Async_Value(executer) {
|
|
75
|
-
return new Unsafe_Async_Value_Class(executer);
|
|
76
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.make_async = make_async;
|
|
4
|
-
const create_Async_Value_1 = require("./create_Async_Value");
|
|
5
|
-
/**
|
|
6
|
-
* converts a regular value to a {@link Async_Value}
|
|
7
|
-
* @param $ the value
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
function make_async($) {
|
|
11
|
-
return (0, create_Async_Value_1.create_Async_Value)({
|
|
12
|
-
'execute': (on_value) => {
|
|
13
|
-
on_value($);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import * as pt from 'exupery-core-types';
|
|
2
|
-
export type Sync_Tuple_2<T1, T2> = {
|
|
3
|
-
readonly 'first': T1;
|
|
4
|
-
readonly 'second': T2;
|
|
5
|
-
};
|
|
6
|
-
export declare function resolve_async_tuple_2<T1, T2>(first: pt.Async_Value<T1>, second: pt.Async_Value<T2>): pt.Async_Value<Sync_Tuple_2<T1, T2>>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolve_async_tuple_2 = resolve_async_tuple_2;
|
|
4
|
-
const create_Async_Value_1 = require("./create_Async_Value");
|
|
5
|
-
function resolve_async_tuple_2(first, second) {
|
|
6
|
-
return (0, create_Async_Value_1.create_Async_Value)({
|
|
7
|
-
'execute': (on_value) => {
|
|
8
|
-
let element_1_is_set = false;
|
|
9
|
-
let element_2_is_set = false;
|
|
10
|
-
let elem1;
|
|
11
|
-
let elem2;
|
|
12
|
-
function wrap_up() {
|
|
13
|
-
if (element_1_is_set && element_2_is_set) {
|
|
14
|
-
on_value({ first: elem1, second: elem2 });
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
first.__start((val) => {
|
|
18
|
-
elem1 = val;
|
|
19
|
-
element_1_is_set = true;
|
|
20
|
-
wrap_up();
|
|
21
|
-
});
|
|
22
|
-
second.__start((val) => {
|
|
23
|
-
elem2 = val;
|
|
24
|
-
element_2_is_set = true;
|
|
25
|
-
wrap_up();
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|