exupery-core-internals 0.1.4 → 0.1.6
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 +30 -1
- package/dist/imp/public/create_Async_Value.js +9 -0
- package/dist/imp/public/create_Unsafe_Async_Value.d.ts +17 -0
- package/dist/imp/public/create_Unsafe_Async_Value.js +76 -0
- package/dist/imp/public/dictionary_literal.js +30 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +2 -2
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.array_literal = array_literal;
|
|
4
4
|
const create_asynchronous_processes_monitor_1 = require("../private/create_asynchronous_processes_monitor");
|
|
5
5
|
const create_Async_Value_1 = require("./create_Async_Value");
|
|
6
|
+
const create_Unsafe_Async_Value_1 = require("./create_Unsafe_Async_Value");
|
|
6
7
|
const not_set_1 = require("./not_set");
|
|
7
8
|
const set_1 = require("./set");
|
|
8
9
|
/**
|
|
@@ -19,7 +20,7 @@ class Array_Class {
|
|
|
19
20
|
return $v(entry);
|
|
20
21
|
}));
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
map_async(on_element_value) {
|
|
23
24
|
const data = this.data;
|
|
24
25
|
return (0, create_Async_Value_1.create_Async_Value)({
|
|
25
26
|
'execute': (on_array_value) => {
|
|
@@ -38,6 +39,34 @@ class Array_Class {
|
|
|
38
39
|
}
|
|
39
40
|
});
|
|
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
|
+
}
|
|
41
70
|
//internal methods
|
|
42
71
|
__for_each($i) {
|
|
43
72
|
this.data.forEach(($) => {
|
|
@@ -6,6 +6,15 @@ class Async_Value_Class {
|
|
|
6
6
|
this.executer = executer;
|
|
7
7
|
}
|
|
8
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) {
|
|
9
18
|
return create_Async_Value({
|
|
10
19
|
'execute': (on_value) => {
|
|
11
20
|
this.executer.execute((value) => {
|
|
@@ -0,0 +1,17 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.dictionary_literal = dictionary_literal;
|
|
4
4
|
const create_asynchronous_processes_monitor_1 = require("../private/create_asynchronous_processes_monitor");
|
|
5
5
|
const create_Async_Value_1 = require("./create_Async_Value");
|
|
6
|
+
const create_Unsafe_Async_Value_1 = require("./create_Unsafe_Async_Value");
|
|
6
7
|
const set_1 = require("./set");
|
|
7
8
|
const not_set_1 = require("./not_set");
|
|
8
9
|
const array_literal_1 = require("./array_literal");
|
|
@@ -21,7 +22,7 @@ class Dictionary {
|
|
|
21
22
|
};
|
|
22
23
|
}));
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
+
map_async(on_entry_value) {
|
|
25
26
|
const source = this.source;
|
|
26
27
|
const temp = {};
|
|
27
28
|
return (0, create_Async_Value_1.create_Async_Value)({
|
|
@@ -40,6 +41,34 @@ class Dictionary {
|
|
|
40
41
|
}
|
|
41
42
|
});
|
|
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
|
+
}
|
|
43
72
|
__map_with_key($v) {
|
|
44
73
|
return new Dictionary(this.source.map(($) => {
|
|
45
74
|
return {
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./imp/public/get_location_info";
|
|
|
9
9
|
export * from "./imp/public/resolve_async_tuple_2";
|
|
10
10
|
export * from "./imp/public/make_async";
|
|
11
11
|
export * from "./imp/public/create_Async_Value";
|
|
12
|
+
export * from "./imp/public/create_Unsafe_Async_Value";
|
|
12
13
|
export * from "./imp/public/set";
|
|
13
14
|
export * from "./imp/public/not_set";
|
|
14
15
|
export * from "./imp/public/Error";
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __exportStar(require("./imp/public/get_location_info"), exports);
|
|
|
25
25
|
__exportStar(require("./imp/public/resolve_async_tuple_2"), exports);
|
|
26
26
|
__exportStar(require("./imp/public/make_async"), exports);
|
|
27
27
|
__exportStar(require("./imp/public/create_Async_Value"), exports);
|
|
28
|
+
__exportStar(require("./imp/public/create_Unsafe_Async_Value"), exports);
|
|
28
29
|
__exportStar(require("./imp/public/set"), exports);
|
|
29
30
|
__exportStar(require("./imp/public/not_set"), exports);
|
|
30
31
|
__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.6",
|
|
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.4"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^18.15.3"
|