• 请不要在回答技术问题时复制粘贴 AI 生成的内容
alexapollo
V2EX  ›  程序员

异步的选择: future-promise 还是协程?

  •  
  •   alexapollo ·
    geekan · May 18, 2015 · 4463 views
    This topic created in 4021 days ago, the information mentioned may be changed or developed.

    因为用的是C++,异步写的很烦,所以之前一直用fp,但fp写起来并不够简洁(因为fp框架),这一段切到了协程,但很多人说到协程会有内存上的问题,可能大量使用也有点麻烦。
    可能是比较专业的一个问题,不知道大家怎么看?

    13 replies    2015-05-19 22:39:32 +08:00
    alexapollo
        1
    alexapollo  
    OP
       May 18, 2015
    竟然没人回,是因为太专业了吗。。
    immjun
        2
    immjun  
       May 18, 2015
    我来回一个 推荐用 Go 哈哈~
    janxin
        3
    janxin  
       May 18, 2015
    既然C++,尝试一下Rust吧
    hhkbp2
        4
    hhkbp2  
       May 18, 2015
    没人回是因为问得不对,协程属于异步,属于并发
    ryanking8215
        5
    ryanking8215  
       May 18, 2015
    你指boost的coroutine吗? 配合asio, 效率应该杠杠的。但是cpp的代码好难看...
    fx
        6
    fx  
       May 18, 2015
    协程是来解决并发的吧
    Hyperion
        7
    Hyperion  
       May 18, 2015
    不提实现就讲内存问题就是耍流氓...
    alexapollo
        8
    alexapollo  
    OP
       May 18, 2015
    @hhkbp2 future-promise也是为了解决异步的问题的。。不知道你用在哪?
    @immjun C++是项目决定的,没法改,go倒是听说够神器
    @janxin 同上
    @ryanking8215 十分同感,shit++
    alexapollo
        9
    alexapollo  
    OP
       May 18, 2015
    @fx 解决并发传统方法靠异步,但异步有cb hell,所以引入了fp,协程相当于是代码同步写法可以直接异步化,所以个人感觉比较舒服点
    sivacohan
        10
    sivacohan  
    PRO
       May 19, 2015 via Android
    没看过C++的,在Python2.7 promise可以看成是一个协程的特殊实现
    spacewander
        11
    spacewander  
       May 19, 2015 via Android
    不知道用的什么协程库?虽然名为协程,但是实现不同效果也会不一样……
    话说协程也有需要通信和同步的时候,感觉不一定比fp好用。看接口咯
    6ufq0VLZn0DDkL80
        12
    6ufq0VLZn0DDkL80  
       May 19, 2015
    推荐试试golang,个人认为这种利用协程的同步写法才是未来的潮流
    janxin
        13
    janxin  
       May 19, 2015
    @alexapollo 既然这样,golang也一样的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   916 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 21:17 · PVG 05:17 · LAX 14:17 · JFK 17:17
    ♥ Do have faith in what you're doing.