Skip to content

Commit

Permalink
feat: add 'inherit' execution mode to action-groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Dec 15, 2024
1 parent 24d98ad commit 3a96984
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion companion/lib/Controls/ActionRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class ControlActionRunner {

async runActions(
actions: ActionInstance[],
extras: Omit<RunActionExtras, 'controlId' | 'abortDelayed'>
extras: Omit<RunActionExtras, 'controlId' | 'abortDelayed' | 'executionMode'>
): Promise<void> {
const controller = new AbortController()

Expand All @@ -160,6 +160,7 @@ export class ControlActionRunner {
...extras,
controlId: this.#controlId,
abortDelayed: controller.signal,
executionMode: 'concurrent',
})
.finally(() => {
// If this removes the last chain, trigger a redraw
Expand Down
1 change: 1 addition & 0 deletions companion/lib/Instance/Wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ export interface RunActionExtras {
surfaceId: string | undefined
location: ControlLocation | undefined
abortDelayed: AbortSignal
executionMode: 'sequential' | 'concurrent'
}

export interface VariableDefinitionTmp {
Expand Down
25 changes: 22 additions & 3 deletions companion/lib/Internal/BuildingBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ export class InternalBuildingBlocks implements InternalModuleFragment {
type: 'dropdown',
label: 'Execution mode',
id: 'execution_mode',
default: 'concurrent',
default: 'inherit',
choices: [
{ id: 'inherit', label: 'Inherit' },
{ id: 'concurrent', label: 'Concurrent' },
{ id: 'sequential', label: 'Sequential' },
],
Expand Down Expand Up @@ -172,10 +173,28 @@ export class InternalBuildingBlocks implements InternalModuleFragment {
} else if (action.action === 'action_group') {
if (extras.abortDelayed.aborted) return true

const executeSequential = action.options.execution_mode === 'sequential'
let executeSequential = false
switch (action.options.execution_mode) {
case 'sequential':
executeSequential = true
break
case 'concurrent':
executeSequential = false
break
case 'inherit':
executeSequential = extras.executionMode === 'sequential'
break
default:
this.#logger.error(`Unknown execution mode: ${action.options.execution_mode}`)
}

const newExtras: RunActionExtras = {
...extras,
executionMode: executeSequential ? 'sequential' : 'concurrent',
}

return this.#actionRunner
.runMultipleActions(action.children?.['default'] ?? [], extras, executeSequential)
.runMultipleActions(action.children?.['default'] ?? [], newExtras, executeSequential)
.catch((e) => {
this.#logger.error(`Failed to run actions: ${e.message}`)
})
Expand Down

0 comments on commit 3a96984

Please sign in to comment.