void set_exception(std::exception_ptr ptr) { assert_valid(); std::shared_ptr<void> scope_guard(nullptr, [&](void*){ mImpl.reset(); }); mImpl->mPromise.set_exception(ptr); }
void TestScopeDismiss() { int i = 0; { wild::ScopeGuard scope_guard([&]{ i = 5; }); scope_guard.Dismiss(); } assert(i == 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(); }
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(); }
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 (...) { } } }