Skip to content

Instantly share code, notes, and snippets.

View IZEDx's full-sized avatar
💙
Typescript

Niklas Kühtmann IZEDx

💙
Typescript
View GitHub Profile
### Keybase proof
I hereby claim:
* I am izedx on github.
* I am ized (https://keybase.io/ized) on keybase.
* I have a public key ASDM4YCfwbmgEBtcDqlNtEtbnqBxIkAdzeLjOCnhr79S1Qo
To claim this, I am signing this object:
@IZEDx
IZEDx / immediate-recursive.ts
Created March 15, 2018 05:42
Demonstration of using setImmediate() and async/await-syntax to program recursively without exceeding the maximum call stack size and tail call optimizations
/**
* Adds the passed function to the JavaScript Message Queue to be executed by the Event Loop,
* wraps a Promise around that and resolves any asynchronous values.
* This allows to call a function asynchronously and on the Event Loop, which doesn't grow the call stack,
* but can be used in a synchronous manner using await.
* @param fn The function to be executed, can be async.
* @param args The arguments to be passed to this function.
*/
function immediate<T, K>(fn: (...args: K[]) => T|Promise<T>, ...args: K[]) {