返回信息流在看Java关于异步的章节时,遇到了一个概念叫做 “callback hell”。
> Nonblocking calls are implemented through callbacks. The programmer registers a callback for the action that should occur after a task completes. Of course, if the next action is also asynchronous, the next action after that is in a different callback. Even though the programmer thinks in terms of “first do step 1, then step 2, then step 3,” the program logic can become dispersed in **“callback hell.”** It gets even worse when you have to add error handling. Suppose step 2 is “the user logs in.” You may need to repeat that step since the user can mistype the credentials. Trying to implement such a control flow in a set of callbacks—or to understand it once it has been implemented—can be quite challenging.
大概的意思是说,如果 `ComplecableFuture` 类不提供像 `thenCompose` 这样的方法的话,就可能导致`ComplecableFuture` 与 `ComplecableFuture` 之间彼此嵌套。我不太理解这到底是一个怎样的问题。网上查了一下,但都是以Javascript的代码讲的看不太懂,所以希望有同学能换种方式讲讲。
这是一条镜像帖。来源:北邮人论坛 / java / #62959同步于 2019/11/9
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
【问题】关于"Callback Hell"
youdianer
2019/11/9镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
可以了解一下什么是“continuation passing style”以及它为什么既难以理解又容易犯错。
【 在 youdianer 的大作中提到: 】
: 在看Java关于异步的章节时,遇到了一个概念叫做 “callback hell”。
: > Nonblocking calls are implemented through callbacks. The programmer registers a callback for the action that should occur after a task completes. Of course, if the next action is also asynchronous, the next action after that is in a different callback. Even though the programmer thinks in terms of “first do step 1, then step 2, then step 3,” the program logic can become dispersed in **“callback hell.”** It gets even worse when you have to add error handling. Suppose step 2 is “the user logs in.” You may need to repeat that step since the user can mistype the credentials. Trying to implement such a control flow in a set of callbacks—or to understand it once it has been implemented—can be quite challenging.
: 大概的意思是说,如果 `ComplecableFuture` 类不提供像 `thenCompose` 这样的方法的话,就可能导致`ComplecableFuture` 与 `ComplecableFuture` 之间彼此嵌套。我不太理解这到底是一个怎样的问题。网上查了一下,但都是以Javascript的代码讲的看不太懂,所以希望有同学能换种方式讲讲。