代码拉取完成,页面将自动刷新
AsyncIO is a C++ coroutine helper library based on llvm-5.0's (or above) coroutine feature. AsycnIO v0.2 has two components:
Make sure you have installed llvm 5.0 or above, libc++, libc++abi, libuv and cmake.
brew tap homebrew/versions
brew install --HEAD llvm #this will install libc++ by default
brew install cmake
brew install
sudo apt-get install libuv cmake
# install llvm-5.0 libc++ libc++abi to /usr/local
# download from here http://releases.llvm.org/download.html#5.0.0
cd $ASYNCIO_PATH && mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j 10
make test
make install
There are some examples in asyncio/examples directory. For more detail infomation about specific class, you can check the tests in asyncio/tests directory or just have a look at the code.
Source Code: sleep_sort.cpp
#include <asyncio/asyncio.hpp>
#include <iostream>
using namespace std;
using namespace asyncio;
coro<void> sleepCout(EventLoop *loop, uint64_t value) {
co_await sleep(loop, value);
cout << value << endl;
}
int main() {
EventLoop loop;
cout << "Someone says 'sleep sort' is O(1)?" << endl;
uint64_t max = -1;
for (auto &&v : {5, 1, 9, 7, 3}) {
loop.createTask(sleepCout(&loop, v))->release();
max = max > v ? max : v;
}
loop.callLater(max + 20, [&] { loop.stop(); })->release();
loop.runForever();
cout << "... I think it makes sense! 🤣🤣🤣" << endl;
}
compile it
$ clang -I $ASYNCIO_HEADER_PATH -o sleep_sort -lc++ -std=c++14 -stdlib=libc++ -fcoroutines-ts -lasyncio -L $ASYNCIO_LIB_PATH -rpath $ASYNCIO_LIB_PATH sleep_sort.cpp
$ ./sleep_sort
Someone says 'sleep sort' is O(1)?
1
3
5
7
9
... I think it makes sense! 🤣🤣🤣
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型