@@ -3,12 +3,20 @@ import { execute } from './broker-protection/execute.js';
33import { retry } from '../timer-utils.js' ;
44import { ErrorResponse } from './broker-protection/types.js' ;
55
6- export function ActionExecutorMixin ( BaseClass ) {
7- return class Mixin extends BaseClass {
8- async processActionAndNotify ( action , data , messaging , retryConfig ) {
6+ /**
7+ * @param {typeof ContentFeature } ContentFeatureClass
8+ */
9+ export function ActionExecutorMixin ( ContentFeatureClass ) {
10+ return class Mixin extends ContentFeatureClass {
11+ /**
12+ * @param {any } action
13+ * @param {Record<string, any> } data
14+ * @param {any } retryConfig
15+ */
16+ async processActionAndNotify ( action , data , retryConfig ) {
917 try {
1018 if ( ! action ) {
11- return messaging . notify ( 'actionError' , { error : 'No action found.' } ) ;
19+ return this . messaging . notify ( 'actionError' , { error : 'No action found.' } ) ;
1220 }
1321
1422 const { results, exceptions } = await this . exec ( action , data , retryConfig ) ;
@@ -20,7 +28,7 @@ export function ActionExecutorMixin(BaseClass) {
2028
2129 // if there are no secondary actions, or just no errors in general, just report the parent action
2230 if ( results . length === 1 || errors . length === 0 ) {
23- return messaging . notify ( 'actionCompleted' , { result : parent } ) ;
31+ return this . messaging . notify ( 'actionCompleted' , { result : parent } ) ;
2432 }
2533
2634 // here we must have secondary actions that failed.
@@ -32,13 +40,13 @@ export function ActionExecutorMixin(BaseClass) {
3240 message : 'Secondary actions failed: ' + joinedErrors ,
3341 } ) ;
3442
35- return messaging . notify ( 'actionCompleted' , { result : response } ) ;
43+ return this . messaging . notify ( 'actionCompleted' , { result : response } ) ;
3644 } else {
37- return messaging . notify ( 'actionError' , { error : 'No response found, exceptions: ' + exceptions . join ( ', ' ) } ) ;
45+ return this . messaging . notify ( 'actionError' , { error : 'No response found, exceptions: ' + exceptions . join ( ', ' ) } ) ;
3846 }
3947 } catch ( e ) {
4048 console . log ( 'unhandled exception: ' , e ) ;
41- return messaging . notify ( 'actionError' , { error : e . toString ( ) } ) ;
49+ return this . messaging . notify ( 'actionError' , { error : e . toString ( ) } ) ;
4250 }
4351 }
4452
@@ -80,7 +88,7 @@ export default class BrokerProtection extends ActionExecutorMixin(ContentFeature
8088 init ( ) {
8189 this . messaging . subscribe ( 'onActionReceived' , async ( /** @type {any } */ params ) => {
8290 const { action, data } = params . state ;
83- await this . processActionAndNotify ( action , data , this . messaging , this . retryConfigFor ( action ) ) ;
91+ return await this . processActionAndNotify ( action , data , this . retryConfigFor ( action ) ) ;
8492 } ) ;
8593 }
8694
0 commit comments