exupery-core-async 0.1.11 → 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.
|
@@ -2,7 +2,20 @@ import * as _et from 'exupery-core-types';
|
|
|
2
2
|
import { Safe_Command_Result } from "./Safe_Command_Result";
|
|
3
3
|
export interface Unsafe_Command_Result<E> {
|
|
4
4
|
map_exception<NE>(handle_exception: ($: E) => NE): Unsafe_Command_Result<NE>;
|
|
5
|
-
|
|
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;
|
|
6
19
|
then(handle: () => Unsafe_Command_Result<E>): Unsafe_Command_Result<E>;
|
|
7
20
|
then_dictionary<E2>($: _et.Dictionary<Unsafe_Command_Result<E2>>, aggregate_exceptions: ($: _et.Dictionary<E2>) => E): Unsafe_Command_Result<E>;
|
|
8
21
|
__start(on_success: () => void, on_exception: ($: E) => void): void;
|
|
@@ -31,6 +31,15 @@ class Unsafe_Command_Result_Class {
|
|
|
31
31
|
constructor(executer) {
|
|
32
32
|
this.executer = executer;
|
|
33
33
|
}
|
|
34
|
+
if_exception_then(handle_exception) {
|
|
35
|
+
return new Unsafe_Command_Result_Class({
|
|
36
|
+
'execute': (new_on_success, new_on_exception) => {
|
|
37
|
+
this.executer.execute(new_on_success, ($) => {
|
|
38
|
+
handle_exception($).__start(() => new_on_exception($));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
34
43
|
catch(handle_exception) {
|
|
35
44
|
return (0, execute_safe_command_1.__execute_safe_command)({
|
|
36
45
|
'execute': (new_on_success) => {
|