UNPKG

@comake/skl-js-engine

Version:

Standard Knowledge Language Javascript Engine

51 lines (42 loc) 1.16 kB
/* eslint-disable func-style */ /* eslint-disable no-console */ import path from 'node:path'; import { JSExecutor } from '../../jsExecutor'; const jsExecutor = new JSExecutor(path.resolve(__dirname, './process.ts'), { async getTime(): Promise<string> { return new Date().toISOString(); } }); const main = async(): Promise<void> => { await jsExecutor.initialize(); try { const result = await jsExecutor.execute( ` async function main() { // Using SKL accessor - this gets converted to request('getTime', ...) return await SKL.getTime({}, { timeout: 50000, retries: 0 }); // Alternative: direct request call (still works) // return await request('getTime', {}, { // timeout: 50000, // retries: 0 // }); } `, {}, { timeout: 50000, functionName: 'main', retries: 0 } ); console.log({ result }); } catch (error) { console.error({ error }); } finally { await jsExecutor.shutdown(); } }; main().catch(console.error);