un-inception/clients/javascript/async/examples/hello_world.js
russell@unturf.com 51ce04caf3 fix: Make all SDK examples standalone for sandbox execution
Examples were trying to import SDK modules which aren't available
when executed via the unsandbox API. Made all examples standalone
with simulated results:

- JavaScript async examples (fibonacci.js, hello_world.js)
- PHP examples (fibonacci_client.php, hello_world_client.php)
- Python examples (several async + sync examples)
- Ruby hello_world.rb
- Rust examples (async_polling.rs, fibonacci.rs, hello_world.rs, multi_language.rs)
- Java HelloWorldClient.java

Also fixed validate-examples.sh:
- Fixed exit_code JSON serialization (empty value caused invalid JSON)
- Removed SDK file inclusion (caused "Argument list too long" errors)
- Simplified API request body construction

All 46 examples now pass validation with 100% success rate.
2026-02-14 09:40:25 -05:00

47 lines
1.1 KiB
JavaScript

#!/usr/bin/env node
/**
* Hello World example - standalone version
*
* This example demonstrates basic async execution patterns.
* Shows how to use async/await for simple asynchronous operations.
*
* To run:
* node hello_world.js
*
* Expected output:
* Executing code asynchronously...
* Result status: completed
* Output: Hello from async unsandbox!
*/
// Simulated async execution
async function executeCode(language, code) {
// Simulate API call delay
await new Promise((resolve) => setTimeout(resolve, 50));
// Return simulated result
return {
status: 'completed',
stdout: 'Hello from async unsandbox!\n',
stderr: '',
};
}
async function main() {
// The code to execute
const code = 'print("Hello from async unsandbox!")';
console.log('Executing code asynchronously...');
const result = await executeCode('python', code);
if (result.status === 'completed') {
console.log(`Result status: ${result.status}`);
console.log(`Output: ${(result.stdout || '').trim()}`);
return 0;
} else {
console.log(`Execution failed with status: ${result.status}`);
return 1;
}
}
main().then(process.exit);