Comments (1)
Updated your example: https://godbolt.org/z/8eheK6Kz7
Looks like -fconcepts
is not playing well with the library.
#include <iostream>
#include <utility>
#include <unifex/async_scope.hpp>
#include <unifex/inline_scheduler.hpp>
#include <unifex/just.hpp>
#include <unifex/just_error.hpp>
#include <unifex/just_from.hpp>
#include <unifex/let_error.hpp>
#include <unifex/let_value.hpp>
#include <unifex/static_thread_pool.hpp>
#include <unifex/sync_wait.hpp>
#include <unifex/then.hpp>
#include <unifex/upon_error.hpp>
#include <unifex/when_all.hpp>
using namespace unifex;
template <typename Handler>
struct on_error {
Handler h;
on_error(Handler h) : h(std::move(h)) {}
template <typename Sender>
friend auto operator|(Sender&& sender, on_error error) {
return sender | let_error([](auto v) { return just_error(v); }) |
upon_error([error = std::move(error)](auto exptr) {
try {
rethrow_exception(exptr);
} catch (std::runtime_error e) {
std::cout << e.what() << "\n";
}
error.h();
});
}
};
int main() {
auto add_42 = then(just_from([]() noexcept {
std::cout << "Hello world! Have an int.\n";
return 13;
}),
[](auto&& arg) noexcept { std::cout << arg + 42 << "\n"; });
auto leterror = add_42 | on_error([]() { std::cout << "hello"; });
async_scope scope;
scope.spawn(std::move(leterror));
sync_wait(scope.complete());
// auto(i) = sync_wait(std::move(leterror)).value(); // 5
}
/*
Output:
ASM generation compiler returned: 0
Execution build compiler returned: 0
Program returned: 0
Hello world! Have an int.
55
*/
from libunifex.
Related Issues (20)
- how to cancel task in static_thread_pool queue? HOT 3
- link error observed HOT 1
- Question: why does my scheduler fail the scheduler concept? HOT 4
- How to format code-style HOT 5
- update `.clang-format` and re-format everything
- Differences between libunifex and stdexec
- improve `fused_stop_source`
- Arithmetic exception in example io_epoll_test HOT 1
- rm `std::terminate` branch from `stop_when`
- Templatize range_stream HOT 1
- detail/types.hpp has what looks like a bad merge
- Clean up when_all.hpp
- Get rid of `config.hpp.in`
- There is different storage class about unifex::schedule. HOT 1
- implement `next_adapt_stream` / `cleanup_adapt_stream` in terms of `adapt_stream`
- Clean up TODO's in scheduler affinity revamp
- flat combining for async_mutex
- Cleanup `io_uring_context`
- at_coroutine_exit can probably break scheduler affinity
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libunifex.