Skip to content

Instantly share code, notes, and snippets.



Last active Jan 29, 2020
What would you like to do?
Bootstrapper (chassis pattern) with a restarting capabilities for TypeScript/Javascript using 'top-level' async/await.
// random bootstrapper for any theoretical ts/js application
const timeout = (millis: number, fn: () => void) => new Promise(c => setTimeout(c, millis)).then(fn);
(async function boot() {
// this try-catch is an additional safety net used for (poorly) written applications in which errors
// are not properly caught
try {
// some random loading of initial components
const config = {}; // some fs load config from disc
// call some main function once done booting and inject hypothetical config
} catch (err) {
// timeout magic'I seem to be crashed, rebooting...');
// await a timeout before rebooting to make sure we dont spam logs, let the environment 'settle', etc...
await timeout(10000, boot);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment