Skip to content

co v2.0.1 released

Compare
Choose a tag to compare
@idealvin idealvin released this 12 Aug 16:55
· 656 commits to master since this release

Documents

New features

  • xrepo
xrepo install -f "openssl=true,libcurl=true" co
  • vcpkg
vcpkg install co:x64-windows

# http & ssl support
vcpkg install co[libcurl,openssl]:x64-windows
  • defer (similar to defer in golang)
#include "co/defer.h"
Timer t;
defer(LOG << "time elapse: " << t.us() << "us");
  • channel for coroutine (similar to channel in golang)
#include "co/co.h"

DEF_main(argc, argv) {
    co::Chan<int> ch;
    go([ch]() {
        ch << 7;
    });

    int v = 0;
    ch >> v;
    LOG << "v: "<< v;

    return 0;
}
  • waitgroup (similar to sync.WaitGroup in golang)
#include "co/co.h"

DEF_main(argc, argv) {
    FLG_cout = true;

    co::WaitGroup wg;
    wg.add(8);

    for (int i = 0; i <8; ++i) {
        go([wg]() {
            LOG << "co: "<< co::coroutine_id();
            wg.done();
        });
    }

    wg.wait();
    return 0;
}
  • Coroutine hook for windows.

  • Create coroutines in specified scheduler(thread).

auto s = co::next_scheduler();
s->go(f1);
s->go(f2);
  • Create coroutine in all schedulers.
auto& s = co::all_schedulers();
for (size_t i = 0; i <s.size(); ++i) {
    s[i]->go(f);
}
  • Add void flag::init(const fastring& path);

Changed

  • Closure to co::Closure.

  • Improve co::Event, can be used anywhere, and support copy constructor and capture by value in lambda.

  • Improve co::Mutex, co::Pool, support copy constructor and capture by value in lambda.

  • co::close() now can be called anywhere, not necessary to call it in the thread that performed the IO operations.

  • Partial support for mingw. Coroutine and coroutine-based features do not work for mingw at present.

Bugs fixed

  • fix bug in fs::file when read/write more than 4G bytes.

  • fix connect timeout error for http::Client.

  • fix link problem in #165.