Coder Social home page Coder Social logo

batch_await about coobjc HOT 5 CLOSED

alibaba avatar alibaba commented on May 17, 2024
batch_await

from coobjc.

Comments (5)

JinjunHan avatar JinjunHan commented on May 17, 2024

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

from coobjc.

NianJi avatar NianJi commented on May 17, 2024

Fixed: #27

from coobjc.

JinjunHan avatar JinjunHan commented on May 17, 2024

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

from coobjc.

NianJi avatar NianJi commented on May 17, 2024
  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];
     
});

from coobjc.

NianJi avatar NianJi commented on May 17, 2024

I open a issue to discuss this: #30

from coobjc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.