@@ -5,6 +5,7 @@ import type { ControlEntityInstance } from './Entities/EntityInstance.js'
55import LogController from '../Log/Controller.js'
66import type { InternalController } from '../Internal/Controller.js'
77import type { InstanceController } from '../Instance/Controller.js'
8+ import type { VariableValue } from '@companion-app/shared/Model/Variables.js'
89
910/**
1011 * Class to handle execution of actions.
@@ -33,24 +34,26 @@ export class ActionRunner {
3334 }
3435
3536 /**
36- * Run a single action
37+ * Run a single action and return its result
3738 */
38- async #runAction( action : ControlEntityInstance , extras : RunActionExtras ) : Promise < void > {
39+ async #runAction( action : ControlEntityInstance , extras : RunActionExtras ) : Promise < VariableValue > {
3940 this . #logger. silly ( 'Running action' , action )
4041
4142 if ( action . connectionId === 'internal' ) {
4243 await this . #internalModule. executeAction ( action , extras )
43- } else {
44- const instance = this . #instanceController. processManager . getConnectionChild ( action . connectionId )
45- if ( instance ) {
46- const entityModel = action . asEntityModel ( false )
47- if ( entityModel . type !== EntityModelType . Action )
48- throw new Error ( `Cannot execute entity of type "${ entityModel . type } " as an action` )
49- await instance . actionRun ( entityModel , extras )
50- } else {
51- this . #logger. silly ( 'trying to run action on a missing instance.' , action )
52- }
44+ return undefined
5345 }
46+
47+ const instance = this . #instanceController. processManager . getConnectionChild ( action . connectionId )
48+ if ( instance ) {
49+ const entityModel = action . asEntityModel ( false )
50+ if ( entityModel . type !== EntityModelType . Action )
51+ throw new Error ( `Cannot execute entity of type "${ entityModel . type } " as an action` )
52+ return instance . actionRun ( entityModel , extras )
53+ }
54+
55+ this . #logger. silly ( 'trying to run action on a missing instance.' , action )
56+ return undefined
5457 }
5558
5659 /**
@@ -60,25 +63,28 @@ export class ActionRunner {
6063 actions0 : ControlEntityInstance [ ] ,
6164 extras : RunActionExtras ,
6265 executeSequential = false
63- ) : Promise < void > {
66+ ) : Promise < VariableValue > {
6467 const actions = actions0 . filter ( ( act ) => act . type === EntityModelType . Action && ! act . disabled )
65- if ( actions . length === 0 ) return
68+ if ( actions . length === 0 ) return undefined
6669
67- if ( extras . abortDelayed . aborted ) return
70+ if ( extras . abortDelayed . aborted ) return undefined
6871
6972 if ( executeSequential ) {
7073 // Future: abort on error?
7174
7275 for ( const action of actions ) {
7376 if ( extras . abortDelayed . aborted ) break
74- await this . #runAction( action , extras ) . catch ( ( e ) => {
77+ extras . previousResult = await this . #runAction( action , extras ) . catch ( ( e ) => {
7578 this . #logger. silly ( `Error executing action for ${ action . connectionId } : ${ e . message ?? e } ` )
79+ return undefined
7680 } )
7781 }
82+
83+ return extras . previousResult
7884 } else {
7985 const groupedActions = this . #splitActionsAroundWaits( actions )
8086
81- const ps : Promise < void > [ ] = [ ]
87+ const ps : Promise < VariableValue > [ ] = [ ]
8288
8389 for ( const { waitAction, actions } of groupedActions ) {
8490 if ( extras . abortDelayed . aborted ) break
@@ -97,13 +103,15 @@ export class ActionRunner {
97103 ps . push (
98104 this . #runAction( action , extras ) . catch ( ( e ) => {
99105 this . #logger. silly ( `Error executing action for ${ action . connectionId } : ${ e . message ?? e } ` )
106+ return undefined
100107 } )
101108 )
102109 }
103110 }
104111
105112 // Await all the actions, so that the abort signal is respected and the promise is pending until all actions are done
106113 await Promise . all ( ps )
114+ return undefined
107115 }
108116 }
109117
@@ -155,7 +163,7 @@ export class ControlActionRunner {
155163 async runActions (
156164 actions : ControlEntityInstance [ ] ,
157165 extras : Omit < RunActionExtras , 'controlId' | 'abortDelayed' | 'executionMode' >
158- ) : Promise < void > {
166+ ) : Promise < VariableValue > {
159167 const controller = new AbortController ( )
160168
161169 const chainId = nanoid ( )
0 commit comments