Commit 3e05ecc2 authored by Kirk Shoop's avatar Kirk Shoop Committed by Facebook Github Bot

Merging examples (#17)

fbshipit-source-id: 0e4317ea86a60c50408cf415972bd048596ac0b2
parent 39d4be19
...@@ -3,22 +3,22 @@ ...@@ -3,22 +3,22 @@
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
#include <defer.h> #include <pushmi/o/defer.h>
#include <share.h> #include <pushmi/o/share.h>
#include <pushmi/o/just.h> #include <pushmi/o/just.h>
#include <pushmi/o/tap.h> #include <pushmi/o/tap.h>
using namespace pushmi::aliases; using namespace pushmi::aliases;
// three models of submission deferral // three models of submission deferral
// (none of these use an executor, they are all running // (none of these use an executor, they are all running
// synchronously on the main thread) // synchronously on the main thread)
// this constructs eagerly and submits just() lazily // this constructs eagerly and submits just() lazily
auto defer_execution() { auto defer_execution() {
printf("construct just\n"); printf("construct just\n");
return op::just(42) | return op::just(42) |
op::tap([](int v){ printf("just - %d\n", v); }); op::tap([](int v){ printf("just - %d\n", v); });
} }
...@@ -36,7 +36,7 @@ auto eager_execution() { ...@@ -36,7 +36,7 @@ auto eager_execution() {
int main() int main()
{ {
printf("\ncall defer_execution\n"); printf("\ncall defer_execution\n");
auto de = defer_execution(); auto de = defer_execution();
printf("submit defer_execution\n"); printf("submit defer_execution\n");
...@@ -67,6 +67,3 @@ int main() ...@@ -67,6 +67,3 @@ int main()
std::cout << "OK" << std::endl; std::cout << "OK" << std::endl;
// OK // OK
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <pool.h> #include <pool.h>
#include <request_via.h> #include <pushmi/o/request_via.h>
#include <pushmi/o/tap.h> #include <pushmi/o/tap.h>
#include <pushmi/o/transform.h> #include <pushmi/o/transform.h>
...@@ -14,7 +14,7 @@ using namespace pushmi::aliases; ...@@ -14,7 +14,7 @@ using namespace pushmi::aliases;
template<class Io> template<class Io>
auto io_operation(Io io) { auto io_operation(Io io) {
return io | return io |
op::transform([](auto){ return 42; }) | op::transform([](auto){ return 42; }) |
op::tap([](int v){ printf("io pool producing, %d\n", v); }) | op::tap([](int v){ printf("io pool producing, %d\n", v); }) |
op::request_via(); op::request_via();
...@@ -28,13 +28,13 @@ int main() ...@@ -28,13 +28,13 @@ int main()
auto io = ioPool.executor(); auto io = ioPool.executor();
auto cpu = cpuPool.executor(); auto cpu = cpuPool.executor();
io_operation(io).via([cpu]{ return cpu; }) | io_operation(io).via([cpu]{ return cpu; }) |
op::tap([](int v){ printf("cpu pool processing, %d\n", v); }) | op::tap([](int v){ printf("cpu pool processing, %d\n", v); }) |
op::submit(); op::submit();
// when the caller is not going to process the result (only side-effect matters) // when the caller is not going to process the result (only side-effect matters)
// or the caller is just going to push the result into a queue. // or the caller is just going to push the result into a queue.
// provide a way to skip the transition to a different executor and make it // provide a way to skip the transition to a different executor and make it
// stand out so that it has to be justified in code reviews. // stand out so that it has to be justified in code reviews.
mi::via_cast<mi::is_sender<>>(io_operation(io)) | op::submit(); mi::via_cast<mi::is_sender<>>(io_operation(io)) | op::submit();
...@@ -43,6 +43,3 @@ int main() ...@@ -43,6 +43,3 @@ int main()
std::cout << "OK" << std::endl; std::cout << "OK" << std::endl;
} }
...@@ -10,6 +10,13 @@ ...@@ -10,6 +10,13 @@
#include <pushmi/executor.h> #include <pushmi/executor.h>
#include <pushmi/trampoline.h> #include <pushmi/trampoline.h>
#if __cpp_deduction_guides >= 201703
#define MAKE(x) x MAKE_
#define MAKE_(...) {__VA_ARGS__}
#else
#define MAKE(x) make_ ## x
#endif
namespace pushmi { namespace pushmi {
using std::experimental::static_thread_pool; using std::experimental::static_thread_pool;
...@@ -38,7 +45,7 @@ public: ...@@ -38,7 +45,7 @@ public:
inline auto executor() { inline auto executor() {
auto exec = execution::require(p.executor(), execution::never_blocking, execution::oneway); auto exec = execution::require(p.executor(), execution::never_blocking, execution::oneway);
return make_time_single_deferred(__pool_submit<decltype(exec)>{exec}); return MAKE(time_single_deferred)(__pool_submit<decltype(exec)>{exec});
} }
inline void stop() {p.stop();} inline void stop() {p.stop();}
......
...@@ -13,12 +13,10 @@ ...@@ -13,12 +13,10 @@
#include <pool.h> #include <pool.h>
#include <request_via.h>
#include <share.h>
#include <pushmi/deferred.h> #include <pushmi/deferred.h>
#include <pushmi/single_deferred.h> #include <pushmi/single_deferred.h>
#include <pushmi/o/just.h> #include <pushmi/o/just.h>
#include <pushmi/o/via.h>
#include <pushmi/o/transform.h> #include <pushmi/o/transform.h>
using namespace pushmi::aliases; using namespace pushmi::aliases;
...@@ -38,8 +36,8 @@ public: ...@@ -38,8 +36,8 @@ public:
}; };
namespace p1054 { namespace p1054 {
// A promise refers to a promise and is associated with a future, // A promise refers to a promise and is associated with a future,
// either through type-erasure or through construction of an // either through type-erasure or through construction of an
// underlying promise with an overload of make_promise_contract(). // underlying promise with an overload of make_promise_contract().
// make_promise_contract() cannot be written to produce a lazy future. // make_promise_contract() cannot be written to produce a lazy future.
...@@ -103,4 +101,3 @@ int main() ...@@ -103,4 +101,3 @@ int main()
std::cout << "OK" << std::endl; std::cout << "OK" << std::endl;
} }
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
#include <pool.h> #include <pool.h>
#include <request_via.h>
#include <share.h>
#include <pushmi/deferred.h> #include <pushmi/deferred.h>
#include <pushmi/single_deferred.h> #include <pushmi/single_deferred.h>
#include <pushmi/o/transform.h> #include <pushmi/o/transform.h>
...@@ -22,8 +19,8 @@ ...@@ -22,8 +19,8 @@
using namespace pushmi::aliases; using namespace pushmi::aliases;
namespace p1054 { namespace p1054 {
// A promise refers to a promise and is associated with a future, // A promise refers to a promise and is associated with a future,
// either through type-erasure or through construction of an // either through type-erasure or through construction of an
// underlying promise with an overload of make_promise_contract(). // underlying promise with an overload of make_promise_contract().
// make_promise_contract() cannot be written to produce a lazy future. // make_promise_contract() cannot be written to produce a lazy future.
......
...@@ -8625,6 +8625,8 @@ PUSHMI_INLINE_VAR constexpr detail::now_fn top{}; ...@@ -8625,6 +8625,8 @@ PUSHMI_INLINE_VAR constexpr detail::now_fn top{};
// LICENSE file in the root directory of this source tree. // LICENSE file in the root directory of this source tree.
//#include "../single_deferred.h" //#include "../single_deferred.h"
//#include "submit.h"
//#include "extension_operators.h"
namespace pushmi { namespace pushmi {
......
...@@ -6,9 +6,16 @@ ...@@ -6,9 +6,16 @@
// This source code is licensed under the MIT license found in the // This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree. // LICENSE file in the root directory of this source tree.
#include <pushmi/single.h> #include "../single.h"
#include <pushmi/o/submit.h> #include "submit.h"
#include <pushmi/o/extension_operators.h> #include "extension_operators.h"
#if __cpp_deduction_guides >= 201703
#define MAKE(x) x MAKE_
#define MAKE_(...) {__VA_ARGS__}
#else
#define MAKE(x) make_ ## x
#endif
namespace pushmi { namespace pushmi {
...@@ -17,8 +24,8 @@ namespace operators { ...@@ -17,8 +24,8 @@ namespace operators {
PUSHMI_TEMPLATE(class F) PUSHMI_TEMPLATE(class F)
(requires Invocable<F>) (requires Invocable<F>)
auto defer(F f) { auto defer(F f) {
return make_single_deferred( return MAKE(single_deferred)(
constrain(lazy::Receiver<_1>, constrain(lazy::Receiver<_1>,
[f = std::move(f)](auto out) mutable { [f = std::move(f)](auto out) mutable {
auto sender = f(); auto sender = f();
PUSHMI_IF_CONSTEXPR( ((bool)TimeSender<decltype(sender)>) ( PUSHMI_IF_CONSTEXPR( ((bool)TimeSender<decltype(sender)>) (
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
// LICENSE file in the root directory of this source tree. // LICENSE file in the root directory of this source tree.
#include "../single_deferred.h" #include "../single_deferred.h"
#include "submit.h"
#include "extension_operators.h"
namespace pushmi { namespace pushmi {
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
// This source code is licensed under the MIT license found in the // This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree. // LICENSE file in the root directory of this source tree.
#include <pushmi/single.h> #include "../single.h"
#include <pushmi/o/submit.h> #include "submit.h"
#include <pushmi/o/extension_operators.h> #include "extension_operators.h"
#include <pushmi/o/via.h> #include "via.h"
namespace pushmi { namespace pushmi {
...@@ -38,7 +38,7 @@ auto request_via_fn::operator()() const { ...@@ -38,7 +38,7 @@ auto request_via_fn::operator()() const {
namespace operators { namespace operators {
PUSHMI_INLINE_VAR constexpr detail::request_via_fn request_via{}; PUSHMI_INLINE_VAR constexpr detail::request_via_fn request_via{};
} // namespace operators } // namespace operators
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
// This source code is licensed under the MIT license found in the // This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree. // LICENSE file in the root directory of this source tree.
#include <pushmi/single.h> #include "../single.h"
#include <pushmi/o/submit.h> #include "submit.h"
#include <pushmi/o/extension_operators.h> #include "extension_operators.h"
#include <subject.h> #include "../subject.h"
namespace pushmi { namespace pushmi {
...@@ -42,7 +42,7 @@ auto share_fn<T>::operator()() const { ...@@ -42,7 +42,7 @@ auto share_fn<T>::operator()() const {
namespace operators { namespace operators {
template<class T> template<class T>
PUSHMI_INLINE_VAR constexpr detail::share_fn<T> share{}; PUSHMI_INLINE_VAR constexpr detail::share_fn<T> share{};
} // namespace operators } // namespace operators
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment