@push.rocks/smartshell 3.1.0 → 3.2.0

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.
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartshell',
6
- version: '3.1.0',
6
+ version: '3.2.0',
7
7
  description: 'A library for executing shell commands using promises.'
8
8
  };
9
9
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx3QkFBd0I7SUFDOUIsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLHdEQUF3RDtDQUN0RSxDQUFBIn0=
@@ -1,8 +1,20 @@
1
1
  import { Smartshell, type IExecResultStreaming } from './classes.smartshell.js';
2
+ export interface IDeferred<T> {
3
+ resolve: (value?: T | PromiseLike<T>) => void;
4
+ reject: (reason?: any) => void;
5
+ promise: Promise<T>;
6
+ }
2
7
  export declare class SmartExecution {
3
8
  smartshell: Smartshell;
4
9
  currentStreamingExecution: IExecResultStreaming;
5
10
  commandString: string;
11
+ private isRestartInProgress;
12
+ private isAnotherRestartRequested;
6
13
  constructor(commandStringArg: string);
14
+ /**
15
+ * Schedules a restart. If a restart is currently in progress, any additional calls
16
+ * to restart will merge into a single additional restart request, which will only execute
17
+ * once the current restart completes.
18
+ */
7
19
  restart(): Promise<void>;
8
20
  }
@@ -2,18 +2,41 @@ import * as plugins from './plugins.js';
2
2
  import { Smartshell } from './classes.smartshell.js';
3
3
  export class SmartExecution {
4
4
  constructor(commandStringArg) {
5
+ this.isRestartInProgress = false;
6
+ this.isAnotherRestartRequested = false;
5
7
  this.commandString = commandStringArg;
6
8
  }
9
+ /**
10
+ * Schedules a restart. If a restart is currently in progress, any additional calls
11
+ * to restart will merge into a single additional restart request, which will only execute
12
+ * once the current restart completes.
13
+ */
7
14
  async restart() {
8
- if (!this.smartshell) {
9
- this.smartshell = new Smartshell({
10
- executor: 'bash',
11
- });
15
+ if (this.isRestartInProgress) {
16
+ // If there's already a restart in progress, just mark that another restart was requested
17
+ this.isAnotherRestartRequested = true;
18
+ return;
12
19
  }
13
- if (this.currentStreamingExecution) {
14
- await this.currentStreamingExecution.kill();
20
+ this.isRestartInProgress = true;
21
+ try {
22
+ if (!this.smartshell) {
23
+ this.smartshell = new Smartshell({
24
+ executor: 'bash',
25
+ });
26
+ }
27
+ if (this.currentStreamingExecution) {
28
+ await this.currentStreamingExecution.kill();
29
+ }
30
+ this.currentStreamingExecution = await this.smartshell.execStreaming(this.commandString);
31
+ }
32
+ finally {
33
+ this.isRestartInProgress = false;
34
+ }
35
+ // If another restart was requested while we were busy, we handle it now
36
+ if (this.isAnotherRestartRequested) {
37
+ this.isAnotherRestartRequested = false;
38
+ await this.restart();
15
39
  }
16
- this.currentStreamingExecution = await this.smartshell.execStreaming(this.commandString);
17
40
  }
18
41
  }
19
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5zbWFydGV4ZWN1dGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NsYXNzZXMuc21hcnRleGVjdXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSxjQUFjLENBQUE7QUFDdkMsT0FBTyxFQUFFLFVBQVUsRUFBNkIsTUFBTSx5QkFBeUIsQ0FBQztBQUVoRixNQUFNLE9BQU8sY0FBYztJQUt6QixZQUFZLGdCQUF3QjtRQUNsQyxJQUFJL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UMsT0FBTztRQUNsQixJQUFJLElBQUksQ0FBQyxtQkFBbUIsRUFBRSxDQUFDO1lBQzdCLHlGQUF5RjtZQUN6RixJQUFJLENBQUMseUJBQXlCLEdBQUcsSUFBSSxDQUFDO1lBQ3RDLE9BQU87UUFDVCxDQUFDO1FBRUQsSUFBSSxDQUFDLG1CQUFtQixHQUFHLElBQUksQ0FBQztRQUNoQyxJQUFJLENBQUM7WUFDSCxJQUFJLENBQUMsSUFBSSxDQUFDLFVBQVUsRUFBRSxDQUFDO2dCQUNyQixJQUFJLENBQUMsVUFBVSxHQUFHLElBQUksVUFBVSxDQUFDO29CQUMvQixRQUFRLEVBQUUsTUFBTTtpQkFDakIsQ0FBQyxDQUFDO1lBQ0wsQ0FBQztZQUNELElBQUksSUFBSSxDQUFDLHlCQUF5QixFQUFFLENBQUM7Z0JBQ25DLE1BQU0sSUFBSSxDQUFDLHlCQUF5QixDQUFDLElBQUksRUFBRSxDQUFDO1lBQzlDLENBQUM7WUFDRCxJQUFJLENBQUMseUJBQXlCLEdBQUcsTUFBTSxJQUFJLENBQUMsVUFBVSxDQUFDLGFBQWEsQ0FBQyxJQUFJLENBQUMsYUFBYSxDQUFDLENBQUM7UUFDM0YsQ0FBQztnQkFBUyxDQUFDO1lBQ1QsSUFBSSxDQUFDLG1CQUFtQixHQUFHLEtBQUssQ0FBQztRQUNuQyxDQUFDO1FBRUQsd0VBQXdFO1FBQ3hFLElBQUksSUFBSSxDQUFDLHlCQUF5QixFQUFFLENBQUM7WUFDbkMsSUFBSSxDQUFDLHlCQUF5QixHQUFHLEtBQUssQ0FBQztZQUN2QyxNQUFNLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQztRQUN2QixDQUFDO0lBQ0gsQ0FBQztDQUNGIn0=
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@push.rocks/smartshell",
3
3
  "private": false,
4
- "version": "3.1.0",
4
+ "version": "3.2.0",
5
5
  "description": "A library for executing shell commands using promises.",
6
6
  "main": "dist_ts/index.js",
7
7
  "typings": "dist_ts/index.d.ts",
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartshell',
6
- version: '3.1.0',
6
+ version: '3.2.0',
7
7
  description: 'A library for executing shell commands using promises.'
8
8
  }
@@ -1,24 +1,55 @@
1
- import * as plugins from './plugins.js'
1
+ import * as plugins from './plugins.js';
2
2
  import { Smartshell, type IExecResultStreaming } from './classes.smartshell.js';
3
3
 
4
+ export interface IDeferred<T> {
5
+ resolve: (value?: T | PromiseLike<T>) => void;
6
+ reject: (reason?: any) => void;
7
+ promise: Promise<T>;
8
+ }
9
+
4
10
  export class SmartExecution {
5
11
  public smartshell: Smartshell;
6
12
  public currentStreamingExecution: IExecResultStreaming;
7
13
  public commandString: string;
8
14
 
15
+ private isRestartInProgress = false;
16
+ private isAnotherRestartRequested = false;
17
+
9
18
  constructor(commandStringArg: string) {
10
19
  this.commandString = commandStringArg;
11
20
  }
12
21
 
13
- public async restart() {
14
- if (!this.smartshell) {
15
- this.smartshell = new Smartshell({
16
- executor: 'bash',
17
- });
22
+ /**
23
+ * Schedules a restart. If a restart is currently in progress, any additional calls
24
+ * to restart will merge into a single additional restart request, which will only execute
25
+ * once the current restart completes.
26
+ */
27
+ public async restart(): Promise<void> {
28
+ if (this.isRestartInProgress) {
29
+ // If there's already a restart in progress, just mark that another restart was requested
30
+ this.isAnotherRestartRequested = true;
31
+ return;
18
32
  }
19
- if (this.currentStreamingExecution) {
20
- await this.currentStreamingExecution.kill();
33
+
34
+ this.isRestartInProgress = true;
35
+ try {
36
+ if (!this.smartshell) {
37
+ this.smartshell = new Smartshell({
38
+ executor: 'bash',
39
+ });
40
+ }
41
+ if (this.currentStreamingExecution) {
42
+ await this.currentStreamingExecution.kill();
43
+ }
44
+ this.currentStreamingExecution = await this.smartshell.execStreaming(this.commandString);
45
+ } finally {
46
+ this.isRestartInProgress = false;
47
+ }
48
+
49
+ // If another restart was requested while we were busy, we handle it now
50
+ if (this.isAnotherRestartRequested) {
51
+ this.isAnotherRestartRequested = false;
52
+ await this.restart();
21
53
  }
22
- this.currentStreamingExecution = await this.smartshell.execStreaming(this.commandString);
23
54
  }
24
55
  }