示例#1
0
文件: main.cpp 项目: CCJY/coliru
    void set_exception(std::exception_ptr ptr)
    {
        assert_valid();

        std::shared_ptr<void> scope_guard(nullptr, [&](void*){
            mImpl.reset();
        });

        mImpl->mPromise.set_exception(ptr);
    }
示例#2
0
void
TestScopeDismiss() {
    int i = 0;
    {
        wild::ScopeGuard scope_guard([&]{
                i = 5;
                });
        scope_guard.Dismiss();
    }
    assert(i == 0);
}
示例#3
0
 void ClientConnection::wrote( const boost::system::error_code& error,
                               size_t bytes_transferred )
 {        
     if (error)
         LOGERROR(LT("Failed to write to "), this->socket->remote_endpoint(), LT(" - transferred "), bytes_transferred, LT(" bytes - "), error.message());
     else
     {
         LOGTRACE(LT("Succesfully wrote "), this->outbox.front(), LT(" to "), this->socket->remote_endpoint());
         boost::lock_guard<boost::mutex> scope_guard(this->outbox_mutex);
         this->outbox.pop_front();
     }
     if( !this->outbox.empty() )
         this->write();  
 }
示例#4
0
    void ClientConnection::writeImpl( std::string message )
    {
        boost::lock_guard<boost::mutex> scope_guard(this->outbox_mutex);

        if (message.back() != '\n')
            message += '\n';
        this->outbox.push_back( message );
        if ( this->outbox.size() > 1 ) {
            // outstanding write
            LOGTRACE(LT("Backlog writing to "), this->socket->remote_endpoint(), LT(" - "), this->outbox.size(), LT(" items awaiting send"));
            return;
        }

        this->write();
    }
示例#5
0
文件: main.cpp 项目: CCJY/coliru
    void set_value(const T& t)
    {
        assert_valid();

        std::shared_ptr<void> scope_guard(nullptr, [&](void*){
            mImpl.reset();
        });

        mImpl->mPromise.set_value(t);
        for (auto& callback : mImpl->mCallbacks)
        {
            try {
                callback(mImpl->mSharedFuture);
            } catch (...) {
            }
        }
    }