MCPcopy Index your code
hub / github.com/MALSync/MALSync / _subroutineAsync

Method _subroutineAsync

src/chibiScript/ChibiConsumer.ts:90–126  ·  view source on GitHub ↗
(script: ChibiJson<any>, startState: any = null)

Source from the content-addressed store, hash-verified

88 }
89
90 async _subroutineAsync(script: ChibiJson<any>, startState: any = null) {
91 this.ctx.setAsyncContext(true);
92 let state: any = startState;
93 // eslint-disable-next-line no-restricted-syntax
94 for (const [functionName, ...args] of script) {
95 if (!functionsRegistry[functionName]) {
96 throw new UnknownChibiFunctionError(functionName);
97 }
98 const func = functionsRegistry[functionName];
99 try {
100 // Resolve chibiJson arguments if necessary
101 for (let i = 0; i < args.length; i += 1) {
102 if (this.isChibiJson(i, functionName, args[i])) {
103 args[i] = await this._subroutineAsync(args[i] as unknown as ChibiJson<any>);
104 }
105 }
106
107 state = func(this.ctx, state, ...args);
108
109 if (state && state instanceof Promise) {
110 state = await state;
111 }
112 } catch (error) {
113 if (error instanceof ChibiError) {
114 throw error;
115 }
116 this.logError(error, functionName, state, args);
117 state = null;
118 }
119
120 if (state && state instanceof ChibiReturn) {
121 return state;
122 }
123 }
124
125 return state;
126 }
127
128 addVariable(name: string, value: any) {
129 this.ctx.set(name, value);

Callers 2

runAsyncMethod · 0.95
runAsyncMethod · 0.80

Calls 3

isChibiJsonMethod · 0.95
logErrorMethod · 0.95
setAsyncContextMethod · 0.80

Tested by

no test coverage detected