Skip to content

Commit

Permalink
Merge pull request #1 from Trebor-Huang/main
Browse files Browse the repository at this point in the history
外科手术
  • Loading branch information
abccsss authored Jun 29, 2022
2 parents 3319dcb + 259ab93 commit 3865df3
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,7 @@ parentPort?.on('message', (value: WorkerData) => {
}
});

function work(data: WorkerData): WorkerResult {
if (data.expiresAt && new Date().getTime() > data.expiresAt) {
return {
taskId: data.taskId ?? 0,
html: '',
data: '',
errors: ['SERVER_IS_BUSY'],
warnings: [],
};
}

export function rawWork(data: WorkerData): WorkerResult {
// Reconstruct the Context object from JSON data
if (data.options?.equationMode) data.options.inline = true;

Expand Down Expand Up @@ -87,10 +77,24 @@ function work(data: WorkerData): WorkerResult {
let html = context.render(data.renderOptions);

return {
taskId: data.taskId ?? 0,
html,
data: JSON.stringify(context.compilerData),
errors: context.errors.map((e) => e.getMessage('zh')),
warnings: context.warnings.map((e) => e.getMessage('zh')),
};
}

function work(data: WorkerData): WorkerResult {
if (data.expiresAt && new Date().getTime() > data.expiresAt) {
return {
taskId: data.taskId ?? 0,
html: '',
data: '',
errors: ['SERVER_IS_BUSY'],
warnings: [],
};
}
let result = rawWork(data);
result.taskId = data.taskId ?? 0;
return result;
}

0 comments on commit 3865df3

Please sign in to comment.