コード例 #1
0
void worker(promise<int> p) {
  try {
    //何か処理をして結果をpromiseに設定する
    p.set_value(computeSomething());
  } catch(...) {
    //例外が発生したら例外をpromiseに設定する
    p.set_exception(current_exception());
  }
}
コード例 #2
0
    void
    on_write(const std::error_code& ec) {
        CF_DBG("<< write: %s", CF_EC(ec));

        if (ec) {
            session->on_error(ec);
            pr.set_exception(std::system_error(ec));
        } else {
            pr.set_value();
        }
    }
コード例 #3
0
ファイル: t_c11.cpp プロジェクト: zhuhk/test-toys
void t_future(){
  //NOTICE("fut.get");
  //fut.get();

  NOTICE("fut.wait");
  fut.wait();

  thread t1(fut_wait), t2(fut_wait), t3(fut_wait);
  while(true){
    prom = promise<bool>();
    fut = prom.get_future();
    sleep(2);
    prom.set_value(false);
    sleep(3);
  }
  t1.join();
  t2.join();
  t3.join();
}
コード例 #4
0
void
basic_session_t::on_connect(const std::error_code& ec, promise<std::error_code> pr, std::unique_ptr<socket_type>& socket) {
    CF_DBG("<< connect: %s", CF_EC(ec));

    if (ec) {
        state = static_cast<std::uint8_t>(state_t::disconnected);
        transport.synchronize()->reset();
    } else {
        CF_CTX_POP();
        CF_CTX("bR");
        CF_DBG(">> listening for read events ...");

        state = static_cast<std::uint8_t>(state_t::connected);
        auto transport = this->transport.synchronize();
        transport->reset(new transport_type(std::move(socket)));
        pull(*transport);
    }

    pr.set_value(ec);
}
コード例 #5
0
ファイル: asio.cpp プロジェクト: beimprovised/Boost.CMT
 void read_write_handler( const promise<size_t>::ptr& p, const boost::system::error_code& ec, size_t bytes_transferred ) {
     if( !ec ) p->set_value(bytes_transferred);
     else p->set_exception( boost::copy_exception( boost::system::system_error(ec) ) );
 }
コード例 #6
0
ファイル: asio.cpp プロジェクト: beimprovised/Boost.CMT
 void error_handler( const promise<boost::system::error_code>::ptr& p, 
                       const boost::system::error_code& ec ) {
     p->set_value(ec);
 }
コード例 #7
0
ファイル: FuturePromise.cpp プロジェクト: QiTai/CPP_Thread
 void calculate()
 {
     this_thread::sleep_for(chrono::milliseconds(1000));
     fut=the_answer_to_life_the_universe_and_everything.get_future();
     the_answer_to_life_the_universe_and_everything.set_value(42);
 }
コード例 #8
0
ファイル: NThreadPromise.cpp プロジェクト: evely211/Norman
void worker2(promise<int> prom) {
    printf("this is thread2 \n");
    flag = 2;
    prom.set_value(10);
    printf("thread2 exit\n");
}
コード例 #9
0
ファイル: main.cpp プロジェクト: CCJY/coliru
void foo(promise<unsigned int> p)
{
    sleep(1);
    p.set_value(42);
}
コード例 #10
0
void work2(promise<int> prom) {
    printf("this is thread2\n");  //C++11的线程输出cout没有boost的好,还是会出现乱序,所以采用printf,有点不爽
    flag=2;
    prom.set_value(10);  //线程2设置了共享状态后,线程1才会被唤醒
    printf("thread2 exit\n");
}