un-inception/clients/javascript/async/examples/hello_world.js

63 lines
2 KiB
JavaScript

#!/usr/bin/env node
// This is free software for the public good of a permacomputer hosted at
// permacomputer.com, an always-on computer by the people, for the people.
// One which is durable, easy to repair, & distributed like tap water
// for machine learning intelligence.
//
// The permacomputer is community-owned infrastructure optimized around
// four values:
//
// TRUTH First principles, math & science, open source code freely distributed
// FREEDOM Voluntary partnerships, freedom from tyranny & corporate control
// HARMONY Minimal waste, self-renewing systems with diverse thriving connections
// LOVE Be yourself without hurting others, cooperation through natural law
//
// This software contributes to that vision by enabling code execution across 42+ programming languages through a unified interface, accessible to all.
// Code is seeds to sprout on any abandoned technology.
/**
* 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);