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

如果嵌套请求? #6

Open
zery6 opened this issue May 26, 2016 · 2 comments
Open

如果嵌套请求? #6

zery6 opened this issue May 26, 2016 · 2 comments

Comments

@zery6
Copy link

zery6 commented May 26, 2016

例如:我需要请求2个接口,第二个接口需要第一个接口得到的返回值作为参数,这样如何实现?

@tough1985
Copy link
Owner

我也考虑过嵌套请求的问题,不过目前没有什么头绪,暂时只能在第一个结束的时候调用第二个

@DanteAndroid
Copy link

很简单,用FlatMap:

networkClient.token() // 订阅时请求 token 
    .flatMap(new Func1<String, Observable<Messages>>() {
        @Override
        public Observable<Messages> call(String token) {
            // 根据token,返回 Observable<Messages> 
            return networkClient.messages();
        }
    })
    .subscribe(new Action1<Messages>() {
        @Override
        public void call(Messages messages) {
            // 处理消息 
        }
    });

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

3 participants