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

batch_await #25

Closed
JinjunHan opened this issue Mar 4, 2019 · 5 comments · Fixed by #27
Closed

batch_await #25

JinjunHan opened this issue Mar 4, 2019 · 5 comments · Fixed by #27
Assignees

Comments

@JinjunHan
Copy link

p2

p1

batch_await不会回调,目前是第二个,比第一个快回调时候出现的问题
@JinjunHan
Copy link
Author

感觉只有按数组顺序逐个回调才能成功

@NianJi
Copy link
Collaborator

NianJi commented Mar 5, 2019

Fixed: #27

@JinjunHan
Copy link
Author

如果一个页面需要请求多个接口来组合数据显示UI,那么怎么使用比较好?
1)每个请求用await()的话,结束时候组合数据,就不能并发请求接口。
2)用batch_await()的话,回调数据是数组,遍历时候还需要判断这个结果属于哪个数据,不太优雅。
还有什么其他方法吗?

@NianJi
Copy link
Collaborator

NianJi commented Mar 5, 2019

  1. We have a design problem with Promise, so use promise to realize concurrent is ugly for now.

We expect:

// concurrent
id promise1 = getPromise1();
id promise2 = getPromise2();

id result1 = await(promise1);
id result2 = await(promise2);

But if you alloc your promise with promise:(COPromiseConstructor)constructor method. Promise does not start directly, until await it. So it became not concurrent.

We are trying to fix this problem. If you have a another good suggestion, we may consider it.

  1. Another way is use multiple coroutines, then use channel passing results.
co_launch(^{

      COChan *chan = [COChan chan];
      COChan *chan2 = [COChan chan];

      // first operation
      co_launch(^{

           [chan1 send:result1];
      });

     // second operation
      co_launch(^{

           [chan2 send:result2];
      });

      id result1 = [chan1 receive];
      id result2 = [chan2 receive];
     
});

@NianJi
Copy link
Collaborator

NianJi commented Mar 5, 2019

I open a issue to discuss this: #30

@NianJi NianJi mentioned this issue Mar 18, 2019
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

Successfully merging a pull request may close this issue.

3 participants