Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

可以中断then的future 链吗 #12

Open
nqf opened this issue Jul 1, 2021 · 1 comment
Open

可以中断then的future 链吗 #12

nqf opened this issue Jul 1, 2021 · 1 comment

Comments

@nqf
Copy link

nqf commented Jul 1, 2021

ananas::MakeReadyFuture()
	.Then([] {
		throw std::runtime_error("rrrrrrrrrrrrrrrrrrr");
		return std::string{"Hello1"};
	})
	.Then([](ananas::Try<std::string>&& str) {
		try {
			std::string a = str;
			std::cout << a << std::endl;
			return 100;
		} catch (const std::runtime_error&) {
			std::cout << "xxxxxx" << std::endl;
                           // 希望发生异常以后 退出 这个回调链
			return 888;
		}
	})
	.Then([](int nn) {
		std::cout << nn << std::endl;
	});
@loveyacper
Copy link
Owner

loveyacper commented Jul 15, 2021

目前有点受限制,Then接受的lambda必须以Future为参数,也就是前面的一个Then发起的是另外一个异步操作。
例如:

ananas::MakeReadyFuture()
	.Then([] {
		return ananas::Future<std::string>(); // 返回空的future,表示中断调用链
	})
	.Then([](Try<std::string>&& fut) {
                cout << "Never reach here" << endl;
	});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants