Hacker News new | past | comments | ask | show | jobs | submit login

You can always make a function that sync all async operations: sleep until a global variable is changed by the callback.

A pain, but still not that bad.




Yes, I've used a similar technique myself; however I consider it only a last resort. But doesn't that require your language to have threads? Is it possible to do this in eg. Javascript?


There is no sleep call that i know of in javascript, but you are right it depends on the language and its implementation of sleep.

Edit: although you could emulate a sleep call by setting a (pediodic) timeout


For node.js, there is a module: https://www.npmjs.com/package/deasync


you can't if all code is running in the same thread, as sleeping would prevent any code to run at all.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: