context restartToExecute改成新上下文
This commit is contained in:
parent
d8064e8b64
commit
9048839a1b
|
|
@ -50,6 +50,7 @@ export declare abstract class AsyncContext<ED extends EntityDict> implements Con
|
|||
abstract getCurrentUserId(allowUnloggedIn?: boolean): string | undefined;
|
||||
abstract setCurrentUserId(userId: string | undefined): void;
|
||||
abstract toString(): Promise<string>;
|
||||
abstract getSerializedData(): object;
|
||||
abstract initialize(data?: any, later?: boolean): Promise<void>;
|
||||
abstract allowUserUpdate(): boolean;
|
||||
abstract openRootMode(): () => void;
|
||||
|
|
|
|||
|
|
@ -28,12 +28,9 @@ class AsyncContext {
|
|||
}
|
||||
// 使一个上下文重新开始事务执行,清除历史数据(定时器中使用)
|
||||
async restartToExecute(routine) {
|
||||
const newContext = !this.uuid ? this : {
|
||||
...this,
|
||||
}; // 这里可能有问题,继承的context对象中如果有对象属性会变成指针公用,但是估计目前是跑不到的。by Xc 20231215
|
||||
if (newContext !== this) {
|
||||
console.warn('restartToExecute跑出了非重用当前context的情况,请仔细调试');
|
||||
}
|
||||
const data = this.getSerializedData();
|
||||
const newContext = (new (Object.getPrototypeOf(this).constructor)());
|
||||
await newContext.initialize(data, true);
|
||||
newContext.opRecords = [];
|
||||
newContext.events = {
|
||||
commit: [],
|
||||
|
|
|
|||
|
|
@ -38,12 +38,9 @@ export abstract class AsyncContext<ED extends EntityDict> implements Context {
|
|||
|
||||
// 使一个上下文重新开始事务执行,清除历史数据(定时器中使用)
|
||||
async restartToExecute(routine: (context: this) => Promise<any>) {
|
||||
const newContext = !this.uuid ? this : {
|
||||
...this,
|
||||
}; // 这里可能有问题,继承的context对象中如果有对象属性会变成指针公用,但是估计目前是跑不到的。by Xc 20231215
|
||||
if (newContext !== this) {
|
||||
console.warn('restartToExecute跑出了非重用当前context的情况,请仔细调试');
|
||||
}
|
||||
const data = this.getSerializedData();
|
||||
const newContext = (new (Object.getPrototypeOf(this).constructor)()) as typeof this;
|
||||
await newContext.initialize(data, true);
|
||||
|
||||
newContext.opRecords = [];
|
||||
newContext.events = {
|
||||
|
|
@ -233,6 +230,8 @@ export abstract class AsyncContext<ED extends EntityDict> implements Context {
|
|||
// 此接口将上下文变成可以serialized的字符串
|
||||
abstract toString(): Promise<string>;
|
||||
|
||||
abstract getSerializedData(): object;
|
||||
|
||||
// 此接口将字符串parse成对象再进行初始化
|
||||
// later表示允许延时状态,上下文要处理在时间维度上可能的异常(比如用户token已经注销等)
|
||||
abstract initialize(data?: any, later?: boolean): Promise<void>;
|
||||
|
|
|
|||
Loading…
Reference in New Issue