Fork me on GitHub

@weavejester hi, I have readed a little bit the ring 1.6 async support and I have a question: why the async handlers has two callbacks, one for continue and the other for raise. There are some rationale for this?, I think that it can be simplified just to one callback called next and capture error by the type. In fact, the handling of the value passed to the next callback can be handled using protocols, so allowing to the user define its own behavior...


@niwinz I like having error handling and normal control flow separated. It makes the code clearer as handlers and middlewares don't have to dispatch first (all of them would have to do it).


@niwinz We have respond and raise for much the same reason that we distinguish between the return value and throw. In theory we could return exceptions instead of throwing them, and then dispatch on the type of the return value. In practice, it’s useful to “short-circuit” instead, and allow exceptions to bypass the normal return value mechanism.


If respond also returned exceptions, then we’d have to check the type at each middleware function. Since asynchronous handlers are a performance optimisation, we ideally want a performant implementation. raise allows us to skip the normal processing steps in the same way that throw does.


@weavejester thanks for the explanation, that makes sense 😉