1 #include <so_5_extra/async_op/time_unlimited.hpp> 2 3 #include <so_5/all.hpp> 4 5 #include <test/3rd_party/various_helpers/time_limited_execution.hpp> 6 #include <test/3rd_party/various_helpers/ensure.hpp> 7 8 #include "../ensure_destroyed_stuff.hpp" 9 10 namespace asyncop = ::so_5::extra::async_op::time_unlimited; 11 12 class a_test_t final : public so_5::agent_t 13 { 14 struct completed final : public so_5::signal_t {}; 15 struct cancel final : public so_5::signal_t {}; 16 struct finish final : public so_5::signal_t {}; 17 18 asyncop::cancellation_point_t<test_op_data_t> m_cp; 19 20 public : a_test_t(context_t ctx)21 a_test_t( context_t ctx ) : so_5::agent_t( std::move(ctx) ) 22 { 23 so_subscribe_self() 24 .event( [this]( mhood_t<cancel> ) { 25 m_cp.cancel(); 26 so_5::send< finish >( *this ); 27 } ) 28 .event( [this]( mhood_t<finish> ) { 29 so_deregister_agent_coop_normally(); 30 } ); 31 } 32 33 virtual void so_evt_start()34 so_evt_start() override 35 { 36 m_cp = asyncop::definition_point_t<test_op_data_t>( 37 ::so_5::outliving_mutable(*this) ) 38 .completed_on( 39 *this, 40 so_default_state(), 41 []( mhood_t<completed> ) { 42 ensure_or_die( false, "this should never happen!" ); 43 } ) 44 .activate( [this] { 45 so_5::send< cancel >( *this ); 46 so_5::send< completed >( *this ); 47 } ); 48 } 49 }; 50 main()51int main() 52 { 53 run_with_time_limit( [&] { 54 so_5::launch( [&](so_5::environment_t & env) { 55 env.register_agent_as_coop( 56 env.make_agent< a_test_t >() ); 57 }); 58 59 ensure_or_die( 0 == test_op_data_t::live_items(), 60 "There should not be any live op_data instances" ); 61 }, 62 5 ); 63 64 return 0; 65 } 66 67