exupery-core-async 0.1.7 → 0.1.8

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,3 +1,5 @@
1
+ import { Safe_Command_Result } from "./Safe_Command_Result";
2
+ import { Unsafe_Command_Result } from "./Unsafe_Command_Result";
1
3
  /**
2
4
  * A value that will asynchronously become available.
3
5
  * Similar to the concept of a promise, but with a smaller API.
@@ -9,6 +11,8 @@ export interface Safe_Query_Result<T> {
9
11
  * @param handle_value callback that transforms the actual value into a new Async_Value
10
12
  */
11
13
  then<NT>(handle_value: ($: T) => Safe_Query_Result<NT>): Safe_Query_Result<NT>;
14
+ execute_safe_command(handle_value: ($: T) => Safe_Command_Result): Safe_Command_Result;
15
+ execute_unsafe_command<E>(handle_value: ($: T) => Unsafe_Command_Result<E>): Unsafe_Command_Result<E>;
12
16
  /**
13
17
  * This method is only to be used by resources
14
18
  */
@@ -1,6 +1,8 @@
1
+ import * as _et from 'exupery-core-types';
1
2
  export interface Unsafe_Command_Result<E> {
2
3
  map_exception<NE>(handle_exception: ($: E) => NE): Unsafe_Command_Result<NE>;
3
4
  if_exception_then<NE>(handle_exception: ($: E) => Unsafe_Command_Result<NE>): Unsafe_Command_Result<NE>;
4
5
  then(handle: () => Unsafe_Command_Result<E>): Unsafe_Command_Result<E>;
6
+ do_dictionary<E2>($: _et.Dictionary<Unsafe_Command_Result<E2>>, aggregate_exceptions: ($: _et.Dictionary<E2>) => E): Unsafe_Command_Result<E>;
5
7
  __start(on_success: () => void, on_exception: ($: E) => void): void;
6
8
  }
@@ -1,7 +1,32 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.__execute_unsafe_command = __execute_unsafe_command;
27
+ const _ei = __importStar(require("exupery-core-internals"));
4
28
  const execute_safe_command_1 = require("./execute_safe_command");
29
+ const create_asynchronous_processes_monitor_1 = require("./create_asynchronous_processes_monitor");
5
30
  class Unsafe_Command_Result_Class {
6
31
  constructor(executer) {
7
32
  this.executer = executer;
@@ -33,6 +58,31 @@ class Unsafe_Command_Result_Class {
33
58
  }
34
59
  });
35
60
  }
61
+ do_dictionary($, aggregate_exceptions) {
62
+ let exceptions = {};
63
+ return __execute_unsafe_command({
64
+ 'execute': (on_success, on_exception) => {
65
+ (0, create_asynchronous_processes_monitor_1.create_asynchronous_processes_monitor)((monitor) => {
66
+ $.map(($, key) => {
67
+ monitor['report process started']();
68
+ $.__start(() => {
69
+ monitor['report process finished']();
70
+ }, (e) => {
71
+ exceptions[key] = e;
72
+ monitor['report process finished']();
73
+ });
74
+ });
75
+ }, () => {
76
+ if (Object.keys(exceptions).length === 0) {
77
+ on_success();
78
+ }
79
+ else {
80
+ on_exception(aggregate_exceptions(_ei.dictionary_literal(exceptions)));
81
+ }
82
+ });
83
+ }
84
+ });
85
+ }
36
86
  catch(handle_exception) {
37
87
  return (0, execute_safe_command_1.__execute_safe_command)({
38
88
  'execute': (on_success) => {
package/dist/index.js CHANGED
@@ -102,7 +102,6 @@ exports.command = {
102
102
  on_exception(_ei.dictionary_literal(exceptions));
103
103
  }
104
104
  });
105
- on_success();
106
105
  }
107
106
  });
108
107
  }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.__run_safe_query = __run_safe_query;
4
+ const execute_safe_command_1 = require("./execute_safe_command");
5
+ const execute_unsafe_command_1 = require("./execute_unsafe_command");
4
6
  class Safe_Query_Result_Class {
5
7
  constructor(executer) {
6
8
  this.executer = executer;
@@ -23,6 +25,24 @@ class Safe_Query_Result_Class {
23
25
  }
24
26
  });
25
27
  }
28
+ execute_safe_command(handle_value) {
29
+ return (0, execute_safe_command_1.__execute_safe_command)({
30
+ 'execute': (on_success) => {
31
+ this.executer.execute((value) => {
32
+ handle_value(value).__start(on_success);
33
+ });
34
+ }
35
+ });
36
+ }
37
+ execute_unsafe_command(handle_value) {
38
+ return (0, execute_unsafe_command_1.__execute_unsafe_command)({
39
+ 'execute': (on_success, on_exception) => {
40
+ this.executer.execute((value) => {
41
+ handle_value(value).__start(on_success, on_exception);
42
+ });
43
+ }
44
+ });
45
+ }
26
46
  __start(on_value) {
27
47
  this.executer.execute(on_value);
28
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exupery-core-async",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Corno",
6
6
  "description": "async types for Exupery",