exupery-core-internals 0.1.3 → 0.1.4

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.
@@ -0,0 +1,15 @@
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,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.create_async_registry = create_async_registry;
3
+ exports.create_asynchronous_processes_monitor = create_asynchronous_processes_monitor;
4
4
  /**
5
- * this function provides a callback with a counter as parameter
6
- * when the counter reaches 0, the onEnd callback is called
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
7
8
  *
8
9
  * this function is specifically useful for async map functions
9
10
  *
10
11
  * @param callback this callback creates a scope within which the counter is provided
11
- * @param onEnd this callback will be called when the counter reaches 0
12
+ * @param onEnd this callback will be called when all ongoing operations are finished
12
13
  */
13
- function create_async_registry(registration_phase, on_all_finished) {
14
+ function create_asynchronous_processes_monitor(monitoring_phase, on_all_finished) {
14
15
  let counter = 0;
15
16
  /*
16
17
  * we need to keep track of if the registration phase is ended or not.
@@ -31,14 +32,14 @@ function create_async_registry(registration_phase, on_all_finished) {
31
32
  }
32
33
  }
33
34
  }
34
- registration_phase({
35
- register: () => {
35
+ monitoring_phase({
36
+ 'report process started': () => {
36
37
  if (on_all_finished_has_been_called) {
37
38
  throw new Error("CORE: async call done after context is ready");
38
39
  }
39
40
  counter += 1;
40
41
  },
41
- report_finished: () => {
42
+ 'report process finished': () => {
42
43
  if (counter === 0) {
43
44
  throw new Error("CORE: decrement while counter is 0");
44
45
  }
@@ -1,4 +1,4 @@
1
- import * as pt from "exupery-core-types";
1
+ import * as _et from "exupery-core-types";
2
2
  /**
3
3
  * returns a Exupery array
4
4
  * why is this not the constructor? to call a constructor, you have to use the keyword 'new'. Exupery doesn't use the concept of a class so that keyword should be avoided
@@ -6,4 +6,4 @@ import * as pt from "exupery-core-types";
6
6
  * @param source An array literal
7
7
  * @returns
8
8
  */
9
- export declare function array_literal<T>(source: readonly T[]): pt.Array<T>;
9
+ export declare function array_literal<T>(source: readonly T[]): _et.Array<T>;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.array_literal = array_literal;
4
- const create_async_registry_1 = require("../private/create_async_registry");
5
- const cast_to_async_value_imp_1 = require("./cast_to_async_value_imp");
4
+ const create_asynchronous_processes_monitor_1 = require("../private/create_asynchronous_processes_monitor");
5
+ const create_Async_Value_1 = require("./create_Async_Value");
6
6
  const not_set_1 = require("./not_set");
7
7
  const set_1 = require("./set");
8
8
  /**
@@ -19,34 +19,26 @@ class Array_Class {
19
19
  return $v(entry);
20
20
  }));
21
21
  }
22
- async_map($v) {
23
- // const elements = source.map($v)
24
- // let _isGuaranteedToReturnAResult = true
25
- // source.forEach(($) => {
26
- // if ($)
27
- // })
28
- function array(array, $v) {
29
- const mapped = array.map($v);
30
- return (0, cast_to_async_value_imp_1.cast_to_async_value_imp)({
31
- 'execute': (on_value) => {
32
- const temp = [];
33
- (0, create_async_registry_1.create_async_registry)((registry) => {
34
- mapped.forEach((v) => {
35
- registry.register();
36
- v.__start((v) => {
37
- temp.push(v);
38
- registry.report_finished();
39
- });
22
+ async_map(on_element_value) {
23
+ const data = this.data;
24
+ return (0, create_Async_Value_1.create_Async_Value)({
25
+ 'execute': (on_array_value) => {
26
+ const temp = [];
27
+ (0, create_asynchronous_processes_monitor_1.create_asynchronous_processes_monitor)((registry) => {
28
+ data.map(on_element_value).forEach((v) => {
29
+ registry['report process started']();
30
+ v.__start((v) => {
31
+ temp.push(v);
32
+ registry['report process finished']();
40
33
  });
41
- }, () => {
42
- on_value(array_literal(temp));
43
34
  });
44
- }
45
- });
46
- }
47
- return array(this.data, $v);
35
+ }, () => {
36
+ on_array_value(array_literal(temp));
37
+ });
38
+ }
39
+ });
48
40
  }
49
- /////////
41
+ //internal methods
50
42
  __for_each($i) {
51
43
  this.data.forEach(($) => {
52
44
  $i($);
@@ -7,4 +7,4 @@ export type Executer<T> = {
7
7
  * @param executer the function that produces the eventual value
8
8
  * @returns
9
9
  */
10
- export declare function cast_to_async_value_imp<T>(executer: Executer<T>): pt.Async_Value<T>;
10
+ export declare function create_Async_Value<T>(executer: Executer<T>): pt.Async_Value<T>;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cast_to_async_value_imp = cast_to_async_value_imp;
3
+ exports.create_Async_Value = create_Async_Value;
4
4
  class Async_Value_Class {
5
5
  constructor(executer) {
6
6
  this.executer = executer;
7
7
  }
8
8
  map(handle_value) {
9
- return cast_to_async_value_imp({
9
+ return create_Async_Value({
10
10
  'execute': (on_value) => {
11
11
  this.executer.execute((value) => {
12
12
  handle_value(value).__start(on_value);
@@ -23,6 +23,6 @@ class Async_Value_Class {
23
23
  * @param executer the function that produces the eventual value
24
24
  * @returns
25
25
  */
26
- function cast_to_async_value_imp(executer) {
26
+ function create_Async_Value(executer) {
27
27
  return new Async_Value_Class(executer);
28
28
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dictionary_literal = dictionary_literal;
4
- const create_async_registry_1 = require("../private/create_async_registry");
5
- const cast_to_async_value_imp_1 = require("./cast_to_async_value_imp");
4
+ const create_asynchronous_processes_monitor_1 = require("../private/create_asynchronous_processes_monitor");
5
+ const create_Async_Value_1 = require("./create_Async_Value");
6
6
  const set_1 = require("./set");
7
7
  const not_set_1 = require("./not_set");
8
8
  const array_literal_1 = require("./array_literal");
@@ -21,32 +21,24 @@ class Dictionary {
21
21
  };
22
22
  }));
23
23
  }
24
- async_map($v) {
25
- function imp(dictionary_as_array, $v) {
26
- const mapped = dictionary_as_array.map(($) => {
27
- return {
28
- key: $.key,
29
- value: $v($.value),
30
- };
31
- });
32
- return (0, cast_to_async_value_imp_1.cast_to_async_value_imp)({
33
- 'execute': (on_value) => {
34
- const temp = {};
35
- (0, create_async_registry_1.create_async_registry)((counter) => {
36
- mapped.map(($) => {
37
- counter.register();
38
- $.value.__start((nv) => {
39
- temp[$.key] = nv;
40
- counter.report_finished();
41
- });
24
+ async_map(on_entry_value) {
25
+ const source = this.source;
26
+ const temp = {};
27
+ return (0, create_Async_Value_1.create_Async_Value)({
28
+ 'execute': (on_dictionary_value) => {
29
+ (0, create_asynchronous_processes_monitor_1.create_asynchronous_processes_monitor)((counter) => {
30
+ source.map(($) => {
31
+ counter['report process started']();
32
+ on_entry_value($.value).__start((nv) => {
33
+ temp[$.key] = nv;
34
+ counter['report process finished']();
42
35
  });
43
- }, () => {
44
- on_value(dictionary_literal(temp));
45
36
  });
46
- }
47
- });
48
- }
49
- return imp(this.source, $v);
37
+ }, () => {
38
+ on_dictionary_value(dictionary_literal(temp));
39
+ });
40
+ }
41
+ });
50
42
  }
51
43
  __map_with_key($v) {
52
44
  return new Dictionary(this.source.map(($) => {
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.make_async = make_async;
4
- const cast_to_async_value_imp_1 = require("./cast_to_async_value_imp");
4
+ const create_Async_Value_1 = require("./create_Async_Value");
5
5
  /**
6
6
  * converts a regular value to a {@link Async_Value}
7
7
  * @param $ the value
8
8
  * @returns
9
9
  */
10
10
  function make_async($) {
11
- return (0, cast_to_async_value_imp_1.cast_to_async_value_imp)({
11
+ return (0, create_Async_Value_1.create_Async_Value)({
12
12
  'execute': (on_value) => {
13
13
  on_value($);
14
14
  }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolve_async_tuple_2 = resolve_async_tuple_2;
4
- const cast_to_async_value_imp_1 = require("./cast_to_async_value_imp");
4
+ const create_Async_Value_1 = require("./create_Async_Value");
5
5
  function resolve_async_tuple_2(first, second) {
6
- return (0, cast_to_async_value_imp_1.cast_to_async_value_imp)({
6
+ return (0, create_Async_Value_1.create_Async_Value)({
7
7
  'execute': (on_value) => {
8
8
  let element_1_is_set = false;
9
9
  let element_2_is_set = false;
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export * from "./imp/public/switch_state";
8
8
  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
- export * from "./imp/public/cast_to_async_value_imp";
11
+ export * from "./imp/public/create_Async_Value";
12
12
  export * from "./imp/public/set";
13
13
  export * from "./imp/public/not_set";
14
14
  export * from "./imp/public/Error";
package/dist/index.js CHANGED
@@ -24,7 +24,7 @@ __exportStar(require("./imp/public/switch_state"), exports);
24
24
  __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
- __exportStar(require("./imp/public/cast_to_async_value_imp"), exports);
27
+ __exportStar(require("./imp/public/create_Async_Value"), exports);
28
28
  __exportStar(require("./imp/public/set"), exports);
29
29
  __exportStar(require("./imp/public/not_set"), exports);
30
30
  __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",
3
+ "version": "0.1.4",
4
4
  "license": "ISC",
5
5
  "description": "",
6
6
  "author": "Corno",
@@ -1,14 +0,0 @@
1
- export type I_Async_Registry = {
2
- readonly 'register': () => void;
3
- readonly 'report_finished': () => void;
4
- };
5
- /**
6
- * this function provides a callback with a counter as parameter
7
- * when the counter reaches 0, 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 the counter reaches 0
13
- */
14
- export declare function create_async_registry(registration_phase: ($: I_Async_Registry) => void, on_all_finished: () => void): void;