@quantform/core 0.7.0-beta.32 → 0.7.0-beta.33

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/cli/dev.js CHANGED
@@ -21,7 +21,7 @@ function default_1(name, options) {
21
21
  return;
22
22
  }
23
23
  const script = new script_1.Script(name, [(0, use_execution_mode_1.paperExecutionMode)({ recording: false })]);
24
- const output = yield script.runWhileFinished();
24
+ const output = yield script.run();
25
25
  console.log(output);
26
26
  });
27
27
  }
@@ -3,6 +3,6 @@ export declare class Script {
3
3
  private readonly name;
4
4
  private readonly dependencies;
5
5
  constructor(name: string, dependencies: Dependency[]);
6
- runWhileFinished(): Promise<unknown>;
6
+ run(): Promise<unknown>;
7
7
  }
8
8
  //# sourceMappingURL=script.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../src/cli/internal/script.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAU,MAAM,aAAa,CAAC;AAIjD,qBAAa,MAAM;IAEf,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,UAAU,EAAE;IAGvC,gBAAgB;CAQvB"}
1
+ {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../src/cli/internal/script.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAU,MAAM,aAAa,CAAC;AAIjD,qBAAa,MAAM;IAEf,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,UAAU,EAAE;IAGvC,GAAG;CAyBV"}
@@ -43,12 +43,15 @@ class Script {
43
43
  this.name = name;
44
44
  this.dependencies = dependencies;
45
45
  }
46
- runWhileFinished() {
46
+ run() {
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
48
  const script = yield Promise.resolve(`${(0, path_1.join)((0, workspace_1.buildDirectory)(), this.name)}`).then(s => __importStar(require(s)));
49
49
  const module = new module_1.Module([...(0, core_1.core)(), ...script.onInstall(), ...this.dependencies]);
50
50
  const { act } = yield module.awake();
51
- return yield act(() => (0, rxjs_1.lastValueFrom)(script.onAwake()));
51
+ return yield act(() => {
52
+ process.stdin.resume();
53
+ return (0, rxjs_1.firstValueFrom)((0, rxjs_1.merge)(script.onAwake().pipe((0, rxjs_1.last)()), (0, rxjs_1.fromEvent)(process, 'exit'), (0, rxjs_1.fromEvent)(process, 'SIGINT'), (0, rxjs_1.fromEvent)(process, 'SIGUSR1'), (0, rxjs_1.fromEvent)(process, 'SIGUSR2'), (0, rxjs_1.fromEvent)(process, 'uncaughtException')).pipe((0, rxjs_1.take)(1), (0, rxjs_1.switchMap)(it => { var _a; return (_a = script.onExit()) !== null && _a !== void 0 ? _a : (0, rxjs_1.of)(it); }), (0, rxjs_1.finalize)(() => process.exit(0))));
54
+ });
52
55
  });
53
56
  }
54
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantform/core",
3
- "version": "0.7.0-beta.32",
3
+ "version": "0.7.0-beta.33",
4
4
  "license": "MIT",
5
5
  "author": "Mateusz Majchrzak",
6
6
  "description": "Node.js library for building systematic trading strategies in reactive way.",
package/src/cli/dev.ts CHANGED
@@ -9,7 +9,7 @@ export default async function (name: string, options: any) {
9
9
  }
10
10
 
11
11
  const script = new Script(name, [paperExecutionMode({ recording: false })]);
12
- const output = await script.runWhileFinished();
12
+ const output = await script.run();
13
13
 
14
14
  console.log(output);
15
15
  }
@@ -1,5 +1,14 @@
1
1
  import { join } from 'path';
2
- import { lastValueFrom } from 'rxjs';
2
+ import {
3
+ finalize,
4
+ firstValueFrom,
5
+ fromEvent,
6
+ last,
7
+ merge,
8
+ of,
9
+ switchMap,
10
+ take
11
+ } from 'rxjs';
3
12
 
4
13
  import { core } from '@lib/core';
5
14
  import { Dependency, Module } from '@lib/module';
@@ -12,12 +21,29 @@ export class Script {
12
21
  private readonly dependencies: Dependency[]
13
22
  ) {}
14
23
 
15
- async runWhileFinished() {
24
+ async run() {
16
25
  const script = await import(join(buildDirectory(), this.name));
17
26
  const module = new Module([...core(), ...script.onInstall(), ...this.dependencies]);
18
27
 
19
28
  const { act } = await module.awake();
20
29
 
21
- return await act(() => lastValueFrom(script.onAwake()));
30
+ return await act(() => {
31
+ process.stdin.resume();
32
+
33
+ return firstValueFrom(
34
+ merge(
35
+ script.onAwake().pipe(last()),
36
+ fromEvent(process, 'exit'),
37
+ fromEvent(process, 'SIGINT'),
38
+ fromEvent(process, 'SIGUSR1'),
39
+ fromEvent(process, 'SIGUSR2'),
40
+ fromEvent(process, 'uncaughtException')
41
+ ).pipe(
42
+ take(1),
43
+ switchMap(it => script.onExit() ?? of(it)),
44
+ finalize(() => process.exit(0))
45
+ )
46
+ );
47
+ });
22
48
  }
23
49
  }