@guanghechen/task 1.0.0-beta.1 → 1.0.0-beta.2

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,18 @@
3
3
  All notable changes to this project will be documented in this file. See
4
4
  [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-beta.2](https://github.com/guanghechen/sora/compare/@guanghechen/task@1.0.0-beta.1...@guanghechen/task@1.0.0-beta.2) (2024-03-09)
7
+
8
+ ### Performance Improvements
9
+
10
+ - ✅ update tests
11
+ ([25797d2](https://github.com/guanghechen/sora/commit/25797d26a6e5fd26980501a15312d8830998d734))
12
+
13
+ # Change Log
14
+
15
+ All notable changes to this project will be documented in this file. See
16
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
17
+
6
18
  # [1.0.0-beta.1](https://github.com/guanghechen/sora/compare/@guanghechen/task@1.0.0-alpha.26...@guanghechen/task@1.0.0-beta.1) (2024-03-09)
7
19
 
8
20
  ### Performance Improvements
package/lib/cjs/index.cjs CHANGED
@@ -68,8 +68,19 @@ class TaskStatus extends observable.Observable {
68
68
  const value = this.getSnapshot();
69
69
  return (value & _terminated) > 0;
70
70
  }
71
+ dispose() {
72
+ if (this.terminated) {
73
+ if (!this.disposed)
74
+ super.dispose();
75
+ return;
76
+ }
77
+ this.next(exports.TaskStatusEnum.CANCELLED, { strict: false });
78
+ super.dispose();
79
+ }
71
80
  next(nextStatus, options) {
72
81
  const curStatus = this.getSnapshot();
82
+ if (curStatus === nextStatus)
83
+ return;
73
84
  if (this._verifyTransition(curStatus, nextStatus)) {
74
85
  super.next(nextStatus, options);
75
86
  if ((nextStatus & _terminated) > 0)
@@ -112,7 +123,7 @@ class AtomicTask {
112
123
  this.status.next(exports.TaskStatusEnum.RUNNING);
113
124
  this._promise = this.run()
114
125
  .then(() => {
115
- this.status.next(exports.TaskStatusEnum.COMPLETED);
126
+ this.status.next(exports.TaskStatusEnum.COMPLETED, { strict: false });
116
127
  })
117
128
  .catch(error => {
118
129
  const soraError = {
@@ -121,7 +132,7 @@ class AtomicTask {
121
132
  details: error,
122
133
  };
123
134
  this._errors.push(soraError);
124
- this.status.next(exports.TaskStatusEnum.FAILED);
135
+ this.status.next(exports.TaskStatusEnum.FAILED, { strict: false });
125
136
  });
126
137
  }
127
138
  return this._promise;
package/lib/esm/index.mjs CHANGED
@@ -66,8 +66,19 @@ class TaskStatus extends Observable {
66
66
  const value = this.getSnapshot();
67
67
  return (value & _terminated) > 0;
68
68
  }
69
+ dispose() {
70
+ if (this.terminated) {
71
+ if (!this.disposed)
72
+ super.dispose();
73
+ return;
74
+ }
75
+ this.next(TaskStatusEnum.CANCELLED, { strict: false });
76
+ super.dispose();
77
+ }
69
78
  next(nextStatus, options) {
70
79
  const curStatus = this.getSnapshot();
80
+ if (curStatus === nextStatus)
81
+ return;
71
82
  if (this._verifyTransition(curStatus, nextStatus)) {
72
83
  super.next(nextStatus, options);
73
84
  if ((nextStatus & _terminated) > 0)
@@ -110,7 +121,7 @@ class AtomicTask {
110
121
  this.status.next(TaskStatusEnum.RUNNING);
111
122
  this._promise = this.run()
112
123
  .then(() => {
113
- this.status.next(TaskStatusEnum.COMPLETED);
124
+ this.status.next(TaskStatusEnum.COMPLETED, { strict: false });
114
125
  })
115
126
  .catch(error => {
116
127
  const soraError = {
@@ -119,7 +130,7 @@ class AtomicTask {
119
130
  details: error,
120
131
  };
121
132
  this._errors.push(soraError);
122
- this.status.next(TaskStatusEnum.FAILED);
133
+ this.status.next(TaskStatusEnum.FAILED, { strict: false });
123
134
  });
124
135
  }
125
136
  return this._promise;
@@ -76,6 +76,7 @@ declare class TaskStatus extends Observable<TaskStatusEnum> implements ITaskStat
76
76
  constructor();
77
77
  get alive(): boolean;
78
78
  get terminated(): boolean;
79
+ dispose(): void;
79
80
  next(nextStatus: TaskStatusEnum, options?: IObservableNextOptions): void;
80
81
  protected _verifyTransition(curStatus: TaskStatusEnum, nextStatus: TaskStatusEnum): boolean;
81
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guanghechen/task",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
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-beta.0",
11
+ "url": "https://github.com/guanghechen/sora/tree/@guanghechen/task@1.0.0-beta.1",
12
12
  "directory": "packages/task"
13
13
  },
14
- "homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/task@1.0.0-beta.0/packages/task#readme",
14
+ "homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/task@1.0.0-beta.1/packages/task#readme",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -36,7 +36,7 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@guanghechen/error.types": "^1.0.1",
39
- "@guanghechen/observable": "^6.0.1"
39
+ "@guanghechen/observable": "^6.0.2"
40
40
  },
41
- "gitHead": "8f4595ed8e3b21ac509a16aeb52cbb686636d9f0"
41
+ "gitHead": "20a6680c86bec2fe654fb53598d6c913707eccfc"
42
42
  }