Earlier quoted context omitted.
If you want to have a specific point to catch an exception, you could write something like this: def start_task(): thread = Thread(do_task) thread.set_error_handler(SpecificErrorType, handler) thread.start()
Yes, but this has a natural analogue in promise land: function startTask() { const promise = doTask(); promise.catch((e) => { if (e instanceof SpecificErrorType) { handler(e); } else { throw e; } }); }
Promises are not neutral enough
51–60 of 133 posts
Re: Promises are not neutral enough
#52I have a feeling the author doesn't understand Promises well. In my opinion, they are in fact designed poorly, but I don't see any problems with points the author describes. He doesn't like that the callback is called immediately - but Promises just represent a result that will be available later and do not guarantee (and should not) when the function will be called. If you want to delay some function call, do it exp…
> This code will just ignore the error. While it is expected that the runtime error would float up and terminate the program - that is what runtime errors are made for. No, this behavior is consistent with how asynchronous programming works in JS. myDiv.addEventListener("click",function(event){ throw "error"; }); Nobody would expect that code to terminate a browser tab on error. > This also makes writing tests more d…
That is because browser environment catches all exceptions and displays them in console. So effectively they become handled exceptions.
Re: Promises are not neutral enough
#53Earlier quoted context omitted.
This is a known footgun of promises. But if you are using async/await, uncaught error in the promise chain is the same as uncaught error inline.
Then the promises should have been advertised as a part of async/await syntax. But many articles promote using them by themselves.
Re: Promises are not neutral enough
#54Promises are classic JS clusterfuck. Replace something shitty, like nested callbacks, with something even more shitty. Thereby ignoring 40 years of experiences of other languages.
Re: Promises are not neutral enough
#55Earlier quoted context omitted.
> This code will just ignore the error. While it is expected that the runtime error would float up and terminate the program - that is what runtime errors are made for. No, this behavior is consistent with how asynchronous programming works in JS. myDiv.addEventListener("click",function(event){ throw "error"; }); Nobody would expect that code to terminate a browser tab on error. > This also makes writing tests more d…
> Nobody would expect that code to terminate a browser tab on error. That is because browser environment catches all exceptions and displays them in console. So effectively they become handled exceptions.
No, it has nothing to do with the developer console. It has everything to do with the fact that async exceptions do not bubble up in the main execution thread. Promises work the exact same way since they existed as libraries long before they were included in the language. It's about consistency, nothing more, nothing less.
Re: Promises are not neutral enough
#56Promises are classic JS clusterfuck. Replace something shitty, like nested callbacks, with something even more shitty. Thereby ignoring 40 years of experiences of other languages.
I don't think that's quite fair. At worst promises are marginally less shitty than callback hell, so long as you don't go nuts and nest them too deeply.
Re: Promises are not neutral enough
#57I can see the automatic unwrapping of Promises to be an issue in some libraries that want to make specific guarantees, but in most of my code this has behaviour has simplified things.
I definitely prefer having Promises and async-await right now over another theoretically sound (but probably more verbose) system available in a couple of years.
Re: Promises are not neutral enough
#58I don't know. André Staltz is a great programmer, but I can't help but think what seems "opinionated" to him about promises boils down to the fact that they don't perfectly match certain quasi-ideological preferences he has about async programming, at the expense of all other concerns. As he states at the end, promises still work, you can get things done and everything is fine. But the part about them being opinionat…
This has nothing to do with it. I love promises but they are truly limiting. Here is an example of how promises limit the power of mobx https://twitter.com/spion/status/958906847385341952 Another example relevant in node is continuation-local-storage (equivalent to threadlocal storage). Implementing it on top of generators or other "chainable / thenable" abstractions is trivially easy. Implementing it on top of nativ…
Re: Promises are not neutral enough
#59I don't know. André Staltz is a great programmer, but I can't help but think what seems "opinionated" to him about promises boils down to the fact that they don't perfectly match certain quasi-ideological preferences he has about async programming, at the expense of all other concerns. As he states at the end, promises still work, you can get things done and everything is fine. But the part about them being opinionat…
The way that promises are implemented actively hurts the ecosystem. Trying to e.g. create a sound typing of the Promise API is really, really hard because of it's auto-flattening nature. This severely hampers languages like TypeScript, Flow & ReasonML that build on top of JavaScript.
Re: Promises are not neutral enough
#60Technically, the API documentation indeed says a Task has Start() methods i.e. is lazy.
But practically, in the majority of cases they are created already in Running or WaitingToRun state. This applies to tasks returned by asynchronous APIs in the framework, tasks implemented by user-written async methods, and tasks started with Task.Run() static methods. Calling Start() on them will throw an exception complaining about the wrong task state. So, in the current versions of .NET, the tasks are eager just like in JS.
I think the lazy tasks are mostly for backward-compatibility with older .NET framework 4.0 that already had tasks but didn’t support async-await.