exupery-core-async 0.1.10 → 0.1.12
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.
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import * as _et from 'exupery-core-types';
|
|
2
|
+
import { Safe_Command_Result } from "./Safe_Command_Result";
|
|
2
3
|
export interface Unsafe_Command_Result<E> {
|
|
3
4
|
map_exception<NE>(handle_exception: ($: E) => NE): Unsafe_Command_Result<NE>;
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* executes a command when an exception has occurred,
|
|
8
|
+
* but stays in the unsafe context
|
|
9
|
+
*
|
|
10
|
+
* this is useful when you want to do some cleanup
|
|
11
|
+
* or logging in case of an exception,
|
|
12
|
+
* but still want to propagate the exception further
|
|
13
|
+
*
|
|
14
|
+
* note that this is different from `catch`,
|
|
15
|
+
* which would switch to the safe context
|
|
16
|
+
*/
|
|
17
|
+
if_exception_then(handle_exception: ($: E) => Safe_Command_Result): Unsafe_Command_Result<E>;
|
|
18
|
+
catch(handle_exception: ($: E) => Safe_Command_Result): Safe_Command_Result;
|
|
5
19
|
then(handle: () => Unsafe_Command_Result<E>): Unsafe_Command_Result<E>;
|
|
6
|
-
|
|
20
|
+
then_dictionary<E2>($: _et.Dictionary<Unsafe_Command_Result<E2>>, aggregate_exceptions: ($: _et.Dictionary<E2>) => E): Unsafe_Command_Result<E>;
|
|
7
21
|
__start(on_success: () => void, on_exception: ($: E) => void): void;
|
|
8
22
|
}
|
|
@@ -4,9 +4,7 @@ export interface Unsafe_Query_Result<T, E> {
|
|
|
4
4
|
map<NT>(handle_value: ($: T) => NT): Unsafe_Query_Result<NT, E>;
|
|
5
5
|
map_exception<NE>(handle_exception: ($: E) => NE): Unsafe_Query_Result<T, NE>;
|
|
6
6
|
then<NT>(handle_value: ($: T) => Unsafe_Query_Result<NT, E>): Unsafe_Query_Result<NT, E>;
|
|
7
|
-
if_exception_then<NE>(handle_exception: ($: E) => Unsafe_Query_Result<T, NE>): Unsafe_Query_Result<T, NE>;
|
|
8
7
|
catch(handle_exception: ($: E) => T): Safe_Query_Result<T>;
|
|
9
|
-
catch_and_map<NT>(handle_value: ($: T) => NT, handle_exception: ($: E) => NT): Safe_Query_Result<NT>;
|
|
10
8
|
execute_unsafe_command(handle_value: ($: T) => Unsafe_Command_Result<E>): Unsafe_Command_Result<E>;
|
|
11
9
|
__start(on_value: ($: T) => void, on_exception: ($: E) => void): void;
|
|
12
10
|
}
|
|
@@ -31,20 +31,20 @@ class Unsafe_Command_Result_Class {
|
|
|
31
31
|
constructor(executer) {
|
|
32
32
|
this.executer = executer;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
if_exception_then(handle_exception) {
|
|
35
35
|
return new Unsafe_Command_Result_Class({
|
|
36
36
|
'execute': (new_on_success, new_on_exception) => {
|
|
37
|
-
this.executer.execute(() => {
|
|
38
|
-
|
|
39
|
-
}
|
|
37
|
+
this.executer.execute(new_on_success, ($) => {
|
|
38
|
+
handle_exception($).__start(() => new_on_exception($));
|
|
39
|
+
});
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
-
'execute': (new_on_success
|
|
43
|
+
catch(handle_exception) {
|
|
44
|
+
return (0, execute_safe_command_1.__execute_safe_command)({
|
|
45
|
+
'execute': (new_on_success) => {
|
|
46
46
|
this.executer.execute(new_on_success, ($) => {
|
|
47
|
-
handle_exception($).__start(new_on_success
|
|
47
|
+
handle_exception($).__start(new_on_success);
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
});
|
|
@@ -58,7 +58,16 @@ class Unsafe_Command_Result_Class {
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
then(handle) {
|
|
62
|
+
return new Unsafe_Command_Result_Class({
|
|
63
|
+
'execute': (new_on_success, new_on_exception) => {
|
|
64
|
+
this.executer.execute(() => {
|
|
65
|
+
handle().__start(new_on_success, new_on_exception);
|
|
66
|
+
}, new_on_exception);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
then_dictionary($, aggregate_exceptions) {
|
|
62
71
|
let exceptions = {};
|
|
63
72
|
return __execute_unsafe_command({
|
|
64
73
|
'execute': (on_success, on_exception) => {
|
|
@@ -83,16 +92,6 @@ class Unsafe_Command_Result_Class {
|
|
|
83
92
|
}
|
|
84
93
|
});
|
|
85
94
|
}
|
|
86
|
-
catch(handle_exception) {
|
|
87
|
-
return (0, execute_safe_command_1.__execute_safe_command)({
|
|
88
|
-
'execute': (on_success) => {
|
|
89
|
-
this.executer.execute(on_success, ($) => {
|
|
90
|
-
handle_exception($);
|
|
91
|
-
on_success();
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
95
|
__start(on_success, on_exception) {
|
|
97
96
|
this.executer.execute(on_success, on_exception);
|
|
98
97
|
}
|
package/dist/run_unsafe_query.js
CHANGED
|
@@ -25,15 +25,6 @@ class Unsafe_Query_Result_Class {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
if_exception_then(handle_exception) {
|
|
29
|
-
return new Unsafe_Query_Result_Class({
|
|
30
|
-
'execute': (new_on_value, new_on_exception) => {
|
|
31
|
-
this.executer.execute(new_on_value, ($) => {
|
|
32
|
-
handle_exception($).__start(new_on_value, new_on_exception);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
28
|
map_exception(handle_exception) {
|
|
38
29
|
return new Unsafe_Query_Result_Class({
|
|
39
30
|
'execute': (on_value, on_exception) => {
|
|
@@ -52,17 +43,6 @@ class Unsafe_Query_Result_Class {
|
|
|
52
43
|
}
|
|
53
44
|
});
|
|
54
45
|
}
|
|
55
|
-
catch_and_map(handle_value, handle_exception) {
|
|
56
|
-
return (0, run_safe_query_1.__run_safe_query)({
|
|
57
|
-
'execute': (on_value) => {
|
|
58
|
-
this.executer.execute(($) => {
|
|
59
|
-
on_value(handle_value($));
|
|
60
|
-
}, ($) => {
|
|
61
|
-
on_value(handle_exception($));
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
46
|
execute_unsafe_command(handle_value) {
|
|
67
47
|
return (0, execute_unsafe_command_1.__execute_unsafe_command)({
|
|
68
48
|
'execute': (on_success, on_exception) => {
|