Comments (5)
感觉只有按数组顺序逐个回调才能成功
from coobjc.
Fixed: #27
from coobjc.
如果一个页面需要请求多个接口来组合数据显示UI,那么怎么使用比较好?
1)每个请求用await()的话,结束时候组合数据,就不能并发请求接口。
2)用batch_await()的话,回调数据是数组,遍历时候还需要判断这个结果属于哪个数据,不太优雅。
还有什么其他方法吗?
from coobjc.
- 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.
- 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];
});
from coobjc.
I open a issue to discuss this: #30
from coobjc.
Related Issues (20)
- await返回以后线程的上下文没有恢复 HOT 3
- 不改代码将IO变异步的问题
- Actors in coswift HOT 2
- 项目凉凉了? HOT 7
- Using Swift Package Manager compile error HOT 1
- fatal error: 'co_queue.h' file not found
- 刚看了swift5.4更新,await以后会变成关键字? HOT 5
- 在.mm 文件里使用编译报错
- COPromise 的 cancle 调用没有效果。 HOT 1
- iOS15.0 cofishhook.c crash HOT 8
- iOS15.0 cofishhook crash. HOT 3
- 【请教】请问coobjc是如何实现完整backtrace的? HOT 2
- demo下载下来运行报错 HOT 2
- 【崩溃】调用co_launch{ } 必现crash HOT 2
- batch_await HOT 2
- cokit compile failed on Xcode 11 HOT 7
- iOS13 crash
- build failed when i use coobjc in xxx.mm
- #import <coobjc.h>写入pch文件导致编译失败
- ios11.1 在co_launch中WebView执行js闪退 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coobjc.