News for hackers. Stuff that matters.
Re:What Color Is Your Function? by totony on Monday February 02, 2015 @04:10PM (#8987006)
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.

Re:What Color Is Your Function? by jakobegger on Monday February 02, 2015 @05:03PM (#8987326)
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?
Re:What Color Is Your Function? by totony on Monday February 02, 2015 @06:49PM (#8987940)
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

Re:What Color Is Your Function? by renekooi on Monday February 02, 2015 @08:48PM (#8988416)
For node.js, there is a module: https://www.npmjs.com/package/deasync
Re:What Color Is Your Function? by radiospiel on Monday February 02, 2015 @05:06PM (#8987339)
you can't if all code is running in the same thread, as sleeping would prevent any code to run at all.