Do you know if native fiber support is planned in a future version of JavaScript? Indeed, it would be very cool if it was possible to write something like :
console.log("sleep 3s...");
const value = wait (resolve, reject) => {
setTimeout(
() => resolve(5),
3_000
);
};
console.log("value =", value); // value = 5 (after 3s)
Of course it is possible to have a similar result with async/await
but the fibers would allow you to pause anywhere in the code without having to be in a function declared async
.
Indeed it can become very problematic to convert a synchronous function into an asynchronous one because it is necessary to transform all the dependencies in cascade:
const a = () => b() + 1;
const b = () => c() + 2;
const c = () => 5;
const value = a();
Ok now c becomes asynchronous...
const a = async () => (await b()) + 1;
const b = async () => (await c()) + 2;
const c = async () => new Promise(resolve => { ... resolve(5) });
const value = await a();
This is a simple example! With fiber, it would be much easier:
const c = () => wait resolve => { ... resolve(5) }
No need to modify a nor b !
PHP has implemented fibers since version 8 :
https://www.php.net/manual/en/language.fibers.php
- Do you know if native fiber support is planned in a future version of JavaScript?
- Do you know if there is a place where we can see the future innovations planned in JavaScript?
- Is there a place where we can propose innovations for JavaScript?
- Do you think that native fiber support would be a good idea?
Thank you in advance!