Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix: fix sequence execution
Wenzhao Hu901abcaae053
diff --git a/packages/core/src/common/promise/sequence.ts b/packages/core/src/common/promise/sequence.tsindex 283af1c7ff..5ff70cceaa 100644--- a/packages/core/src/common/promise/sequence.ts+++ b/packages/core/src/common/promise/sequence.ts@@ -1,7 +1,7 @@/**- *- * @param tasks all promise tasks that need to be triggered- * @returns+ * Execute promise tasks in sequence, if one of the tasks return false, the sequence will be stopped.+ * @param tasks All promise tasks that need to be triggered.+ * @returns Returns `true` if all tasks are executed successfully, otherwise `false` and index of the task that returns false.*/export async function sequence(tasks: Array<() => Promise<boolean> | boolean>@@ -21,6 +21,11 @@ export async function sequence(};}+/**+ * Execute tasks in sequence, if one of the tasks return false, the sequence will be stopped.+ * @param tasks All tasks that need to be triggered.+ * @returns Returns `true` if all tasks are executed successfully, otherwise `false` and index of the task that returns false.+ */export function syncSequence(tasks: Array<() => boolean>): { result: boolean; index: number } {for (const [index, task] of tasks.entries()) {if (!task()) {diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 670ceec9f2..36cea35a92 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -10,6 +10,7 @@ export {type ICommand,type ICommandInfo,ICommandService,+ type IExecutionOptions,type IMultiCommand,type IMutation,type IOperation,diff --git a/packages/core/src/services/command/command.service.ts b/packages/core/src/services/command/command.service.tsindex 695a90a435..d7c5abfb42 100644--- a/packages/core/src/services/command/command.service.ts+++ b/packages/core/src/services/command/command.service.ts@@ -1,6 +1,6 @@import { createIdentifier, IAccessor, IDisposable, Inject, Injector } from '@wendellhu/redi';-import { syncSequence } from '../../common/promise/sequence';+import { sequence, syncSequence } from '../../common/promise/sequence';import { toDisposable } from '../../Shared/lifecycle';import { IKeyValue } from '../../Shared/Types';import { IContextService } from '../context/context.service';@@ -416,7 +416,16 @@ class MultiCommand implements IMultiCommand {};}-export function sequenceExecute(tasks: ICommandInfo[], commandService: ICommandService) {- const promises = tasks.map((task) => () => commandService.syncExecuteCommand(task.id, task.params));+export function sequenceExecute(tasks: ICommandInfo[], commandService: ICommandService, options?: IExecutionOptions) {+ const promises = tasks.map((task) => () => commandService.syncExecuteCommand(task.id, task.params, options));return syncSequence(promises);}++export function sequenceExecuteAsync(+ tasks: ICommandInfo[],+ commandService: ICommandService,+ options?: IExecutionOptions+) {+ const promises = tasks.map((task) => () => commandService.executeCommand(task.id, task.params, options));+ return sequence(promises);+}