Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/georgiifirsov/w32coro
C++14-compatible implementation of coroutines for Windows systems. Based of Win32 API fibers that are manually scheduled by this library.
https://github.com/georgiifirsov/w32coro
coroutines cpp14 cxx14 library winapi
Last synced: 10 days ago
JSON representation
C++14-compatible implementation of coroutines for Windows systems. Based of Win32 API fibers that are manually scheduled by this library.
- Host: GitHub
- URL: https://github.com/georgiifirsov/w32coro
- Owner: GeorgiiFirsov
- License: gpl-3.0
- Created: 2021-04-26T19:44:22.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-05-02T18:58:32.000Z (over 3 years ago)
- Last Synced: 2024-08-10T04:23:18.273Z (3 months ago)
- Topics: coroutines, cpp14, cxx14, library, winapi
- Language: C++
- Homepage:
- Size: 48.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# w32coro
Small hand-written coroutines library. Written in C++14 with Win32 API (Fibers).
## Examples
#### Receiving some information from server```cpp
#include "w32coro/w32coro.h"
#include "MyAwesomeProject.h"int main()
{
const auto ReceiveData = [](const std::wstring& wsServerName, DWORD dwPort) {
IConnectionPtr spConn = Connect(wsServerName, dwPort);
std::wstring wsData = spConn->Receive();
w32coro::CoReturn(wsData);
};
std::wstring wsServerName = L"my.awesome.server";
DWORD dwPort = 8080;
const auto wsReceivedData = w32coro::CoAwait(
w32coro::Coroutine(ReceiveData, std::cref(wsServerName), dwPort));
std::wcout << wsReceivedData << std::endl;
}```
#### Suspending, resuming and returning various values
Actually this example can be extended to write real generator, that implements some methods such as `begin` and `end` to use it in range-based for loop.
```cpp
#include "w32coro/w32coro.h"
#include "MyAwesomeProject.h"int main()
{
const auto Generate = [](size_t Initial) {
while (true) {
w32coro::CoYield(Initial++);
}
};
w32coro::Coroutine gen(Generate, 0);
std::vector Numbers;
for (size_t i = 0; i < 10; i++) {
Numbers.emplace_back(gen.Get());
gen.Resume();
}
//
// Will print 0 1 2 ...
//
for (size_t n : Numbers) {
std::cout << n << ' ';
}
}
```