>One thing that is tricky with async is that nobody tells you if the async function never does what it should
Could you clarify this?
>One thing that is tricky with async is that nobody tells you if the async function never does what it should
Could you clarify this?
But when you call an async-function that is supposed to do something like say write to a file or database maybe there is an error which makes it never do its job, and never call the callback you gave it. But the rest of your program just hums along happily. There is no error. The error does not "happen" but the error is that "something did NOT happen". And when something does not happen you don't get an error or notification saying that something did not happen.
You run your program but expected results do not show up in database. But you don't know why, because the problem is that some of your async functions did NOT call something they should have called.
It's hard to detect that something does not happen.
Some kind of built-in support for callback-timeouts might alleviate this problem.
>maybe there is an error which makes it never do its job
You can throw an error regardless of the reason why it failed to do its job. If the write to the db does not success, you can throw an error.
So your async function never calls fs.write() even though it was your intention that it should. Is that an error? Definitely, the file was never written to, it now has wrong content. But the problem is, as you run your program you do not get any error thrown at you, therefore you don't even know there is a problem. Later on you may, or may not, realize that the content of the file is wrong. And then it's hard to say what caused that error.
What "caused something not to happen" is a difficult question to answer because you can't pinpoint the exact location in time and code where it did not happen. Why? Because it did not happen anywhere, ever :-)
If there is an error when reading a file or accessing a database, unless the file or database API is horrendously designed, it will reject the promise or throw.
I would say it stops unless there is something keeping it running.
Think about your single-page-web-app. When you click on some widget on it a click-handler triggers and executes that code. But then it stops. When the user doesn't interact with your web-app no JavaScript is typically executing, unless you have set up a repeating polling loop with setInterval().
I don't think using explicit callbacks helps, though, which has the same potential issue (worse really, since you're probably handling callbacks directly more often, depending on the patterns you use).
It helped to detect some flaws in my program.
A similar thing could no doubt be done with promises. But I think the best solution would be if there was a built-in facility to detect callbacks that were not called within a required or default time interval.
Eventually I stopped using the timeout wrapper, it didn't help very much, but made the code more complex. More but easier to understand code is often my preferred choice.
Whereas if language itself offers built-in facilities then fine since they are more likely to be bugfree than my own code.
But I assume in a thread-based language like Java all asynchronicity happens due to threads. Then from the programmers' point of view method-calls always either return a result or throw an error. They don't just silently stop executing