@guanghechen/task 1.0.0-alpha.7 → 1.0.0-alpha.9

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/CHANGELOG.md CHANGED
@@ -3,6 +3,29 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-alpha.9](https://github.com/guanghechen/sora/compare/@guanghechen/task@1.0.0-alpha.8...@guanghechen/task@1.0.0-alpha.9) (2023-09-16)
7
+
8
+
9
+ ### Performance Improvements
10
+
11
+ * 🎨 expand monitors into smaller properties ([28179bf](https://github.com/guanghechen/sora/commit/28179bf6ab0904c5b669e33fbadc9f13f12ccab7))
12
+ * ⬆️ upgrade dependencies ([a259feb](https://github.com/guanghechen/sora/commit/a259feba5933148a34e4f498c9b883a5f87b7b50))
13
+
14
+
15
+
16
+
17
+
18
+ # [1.0.0-alpha.8](https://github.com/guanghechen/sora/compare/@guanghechen/task@1.0.0-alpha.7...@guanghechen/task@1.0.0-alpha.8) (2023-09-14)
19
+
20
+
21
+ ### Performance Improvements
22
+
23
+ * ⬆️ upgrade dependencies ([0af59d8](https://github.com/guanghechen/sora/commit/0af59d85d8c2c514f57e5289e87f0a3cbb6ab5ab))
24
+
25
+
26
+
27
+
28
+
6
29
  # [1.0.0-alpha.7](https://github.com/guanghechen/sora/compare/@guanghechen/task@1.0.0-alpha.6...@guanghechen/task@1.0.0-alpha.7) (2023-09-07)
7
30
 
8
31
 
package/lib/cjs/index.cjs CHANGED
@@ -20,15 +20,14 @@ const terminated = constant.TaskStatusEnum.CANCELLED |
20
20
  class TaskState {
21
21
  name;
22
22
  _errorCollector;
23
- _monitors;
23
+ _monitorAddError;
24
+ _monitorStatusChange;
24
25
  _status;
25
26
  constructor(name) {
26
27
  this.name = name;
27
28
  this._errorCollector = new error.SoraErrorCollector(name);
28
- this._monitors = {
29
- onAddError: new monitor.Monitor('onAddError'),
30
- onStatusChange: new monitor.Monitor('onStatusChange'),
31
- };
29
+ this._monitorAddError = new monitor.Monitor('onAddError');
30
+ this._monitorStatusChange = new monitor.Monitor('onStatusChange');
32
31
  this._status = constant.TaskStatusEnum.PENDING;
33
32
  }
34
33
  get status() {
@@ -57,7 +56,7 @@ class TaskState {
57
56
  const accepted = this.check(status);
58
57
  if (accepted) {
59
58
  this._status = status;
60
- this._monitors.onStatusChange.notify(status, curStatus);
59
+ this._monitorStatusChange.notify(status, curStatus);
61
60
  }
62
61
  else {
63
62
  throw new TypeError(`[transit] unexpected status: task(${this.name}) cur(${curStatus}) next(${status})`);
@@ -68,8 +67,8 @@ class TaskState {
68
67
  if (this.terminated)
69
68
  return noop;
70
69
  const { onAddError, onStatusChange } = monitor;
71
- const unsubscribeOnAddError = this._monitors.onAddError.subscribe(onAddError);
72
- const unsubscribeOnStatusChange = this._monitors.onStatusChange.subscribe(onStatusChange);
70
+ const unsubscribeOnAddError = this._monitorAddError.subscribe(onAddError);
71
+ const unsubscribeOnStatusChange = this._monitorStatusChange.subscribe(onStatusChange);
73
72
  return () => {
74
73
  unsubscribeOnAddError();
75
74
  unsubscribeOnStatusChange();
@@ -110,12 +109,12 @@ class TaskState {
110
109
  if (!this.terminated)
111
110
  throw new Error(`[cleanup] task(${this.name}) is not terminated`);
112
111
  this._errorCollector.cleanup();
113
- this._monitors.onStatusChange.destroy();
114
- this._monitors.onAddError.destroy();
112
+ this._monitorStatusChange.destroy();
113
+ this._monitorAddError.destroy();
115
114
  }
116
115
  _addError(type, error, level = constant.ErrorLevelEnum.ERROR) {
117
116
  this._errorCollector.add(type, error, level);
118
- this._monitors.onAddError.notify(type, error, level);
117
+ this._monitorAddError.notify(type, error, level);
119
118
  }
120
119
  }
121
120
 
package/lib/esm/index.mjs CHANGED
@@ -19,15 +19,14 @@ const terminated = TaskStatusEnum.CANCELLED |
19
19
  class TaskState {
20
20
  name;
21
21
  _errorCollector;
22
- _monitors;
22
+ _monitorAddError;
23
+ _monitorStatusChange;
23
24
  _status;
24
25
  constructor(name) {
25
26
  this.name = name;
26
27
  this._errorCollector = new SoraErrorCollector(name);
27
- this._monitors = {
28
- onAddError: new Monitor('onAddError'),
29
- onStatusChange: new Monitor('onStatusChange'),
30
- };
28
+ this._monitorAddError = new Monitor('onAddError');
29
+ this._monitorStatusChange = new Monitor('onStatusChange');
31
30
  this._status = TaskStatusEnum.PENDING;
32
31
  }
33
32
  get status() {
@@ -56,7 +55,7 @@ class TaskState {
56
55
  const accepted = this.check(status);
57
56
  if (accepted) {
58
57
  this._status = status;
59
- this._monitors.onStatusChange.notify(status, curStatus);
58
+ this._monitorStatusChange.notify(status, curStatus);
60
59
  }
61
60
  else {
62
61
  throw new TypeError(`[transit] unexpected status: task(${this.name}) cur(${curStatus}) next(${status})`);
@@ -67,8 +66,8 @@ class TaskState {
67
66
  if (this.terminated)
68
67
  return noop;
69
68
  const { onAddError, onStatusChange } = monitor;
70
- const unsubscribeOnAddError = this._monitors.onAddError.subscribe(onAddError);
71
- const unsubscribeOnStatusChange = this._monitors.onStatusChange.subscribe(onStatusChange);
69
+ const unsubscribeOnAddError = this._monitorAddError.subscribe(onAddError);
70
+ const unsubscribeOnStatusChange = this._monitorStatusChange.subscribe(onStatusChange);
72
71
  return () => {
73
72
  unsubscribeOnAddError();
74
73
  unsubscribeOnStatusChange();
@@ -109,12 +108,12 @@ class TaskState {
109
108
  if (!this.terminated)
110
109
  throw new Error(`[cleanup] task(${this.name}) is not terminated`);
111
110
  this._errorCollector.cleanup();
112
- this._monitors.onStatusChange.destroy();
113
- this._monitors.onAddError.destroy();
111
+ this._monitorStatusChange.destroy();
112
+ this._monitorAddError.destroy();
114
113
  }
115
114
  _addError(type, error, level = ErrorLevelEnum.ERROR) {
116
115
  this._errorCollector.add(type, error, level);
117
- this._monitors.onAddError.notify(type, error, level);
116
+ this._monitorAddError.notify(type, error, level);
118
117
  }
119
118
  }
120
119
 
@@ -6,7 +6,8 @@ export { ITask, ITaskError, ITaskMonitor, ITaskState } from '@guanghechen/types'
6
6
  declare class TaskState implements ITaskState {
7
7
  readonly name: string;
8
8
  protected readonly _errorCollector: ISoraErrorCollector;
9
- private readonly _monitors;
9
+ private readonly _monitorAddError;
10
+ private readonly _monitorStatusChange;
10
11
  private _status;
11
12
  constructor(name: string);
12
13
  get status(): TaskStatusEnum;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guanghechen/task",
3
- "version": "1.0.0-alpha.7",
3
+ "version": "1.0.0-alpha.9",
4
4
  "description": "Atomic and resumable tasks",
5
5
  "author": {
6
6
  "name": "guanghechen",
@@ -8,10 +8,10 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/guanghechen/sora/tree/@guanghechen/task@1.0.0-alpha.6",
11
+ "url": "https://github.com/guanghechen/sora/tree/@guanghechen/task@1.0.0-alpha.8",
12
12
  "directory": "packages/task"
13
13
  },
14
- "homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/task@1.0.0-alpha.6/packages/task#readme",
14
+ "homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/task@1.0.0-alpha.8/packages/task#readme",
15
15
  "type": "module",
16
16
  "main": "./lib/cjs/index.cjs",
17
17
  "module": "./lib/esm/index.mjs",
@@ -40,17 +40,17 @@
40
40
  "test": "node --experimental-vm-modules ../../node_modules/.bin/jest --config ../../jest.config.mjs --rootDir ."
41
41
  },
42
42
  "dependencies": {
43
- "@guanghechen/constant": "^1.0.0-alpha.3",
44
- "@guanghechen/error": "^1.0.0-alpha.7",
45
- "@guanghechen/monitor": "^1.0.0-alpha.7",
46
- "@guanghechen/types": "^1.0.0-alpha.4"
43
+ "@guanghechen/constant": "^1.0.0-alpha.5",
44
+ "@guanghechen/error": "^1.0.0-alpha.9",
45
+ "@guanghechen/monitor": "^1.0.0-alpha.9",
46
+ "@guanghechen/types": "^1.0.0-alpha.6"
47
47
  },
48
48
  "devDependencies": {
49
- "@guanghechen/shared": "^1.0.0-alpha.5",
49
+ "@guanghechen/shared": "^1.0.0-alpha.7",
50
50
  "cross-env": "^7.0.3",
51
- "jest": "^29.6.4",
51
+ "jest": "^29.7.0",
52
52
  "rimraf": "^5.0.1",
53
- "rollup": "^3.29.0"
53
+ "rollup": "^3.29.2"
54
54
  },
55
- "gitHead": "041e7862a78703a09006e3038f561c08dea88833"
55
+ "gitHead": "c8f31416915487bc1718dabb550e22009938c3f8"
56
56
  }