Exemple #1
0
    virtual void finish(error_code code, http::status status) {
        m_message_accum.error_code      = code;
        m_message_accum.error_string    = error_buffer;
        m_message_accum.status          = status;

        // call the receive callback a last time with the final
        // error code
        if(m_on_receive) {
            assert(m_message_accum.body.empty());
            m_on_receive(m_message_accum, progress());
        }

        m_send_file.reset();
        m_receive_file.reset();

        // set the final message data so it can be retrieved
        // with the message-future object in the response object
        m_message_promise.set_value(std::move(m_message_accum));

        // call an optional continuation callback for this request
        if(m_on_finish) {
            m_on_finish();
        }

        // mark this request as finished
        finished_promise.set_value();
    }
Exemple #2
0
 void op()  // GB was operator
 {
     try {
         promise.set_value(f());
     } catch(...) {
         promise.set_exception(std::current_exception());
     }
 }
Exemple #3
0
 std::future<int> doit()
 {
   BARK();
   auto cb = [&](const boost::system::error_code&) {
     std::cout << "CB!\n";
     prom.set_value(13);
   };
   dt.async_wait(cb);
   return prom.get_future();
 }
Exemple #4
0
	shared_fence(const vk::vk_logical_device<> &device,
				 T &&val,
				 const char *name,
				 typename std::enable_if<!std::is_void<S>::value>::type* = nullptr)
		: f(device,
			name,
			true), 
		future(promise.get_future().share())
	{
		promise.set_value(std::forward<T>(val));
	}
Exemple #5
0
	shared_fence(const vk::vk_logical_device<> &device, 
				 bool signaled,
				 const char *name,
				 typename std::enable_if<std::is_void<S>::value>::type* = nullptr)
		: f(device, 
			name,
			signaled), 
		future(promise.get_future().share())
	{
		if (signaled)
			promise.set_value();
	}
Exemple #6
0
	/**
	*	@brief	Construct a fence object in unsignaled state
	*/
	shared_fence(const vk::vk_logical_device<> &device,
				 const char *name)
		: f(device, 
			name,
			false), 
		future(promise.get_future().share())
	{}
	void ThreadFunction()
	{
		m_promice.set_value();
		while (true)
		{
			Data data;
			{
				std::unique_lock<std::mutex> lock(m_queueGuard);
				m_condition.wait(lock, [this]()
				{
					return !m_running || !m_queue.empty();
				});
				if (!m_running && m_queue.empty())
					break;

				if (!m_queue.empty())
				{
					m_queue.front().swap(data);
					m_queue.pop();
				}
			}

			for (const auto &d : data)
				Out(m_outp, d);

			m_handler.Saved(data.size());
		}

		m_handler.SaveReady();
	}
Exemple #8
0
void doSomething (std::promise<std::string>& p)
{
    try {
        // read character and throw exception if 'x'
        std::cout << "read char ('x' for exception): ";
        char c = std::cin.get();
        if (c == 'x') {
            throw std::runtime_error(std::string("char ")+c+" read");
        }
        //...
        std::string s = std::string("char ") + c + " processed";
        p.set_value(std::move(s));    // store result
    }
    catch (...) {
        p.set_exception(std::current_exception());  // store exception
    }
}
Exemple #9
0
                void operator()() {
                    osmium::thread::set_thread_name("_osmium_write");

                    try {
                        while (true) {
                            std::string data = m_queue.pop();
                            if (at_end_of_data(data)) {
                                break;
                            }
                            m_compressor->write(data);
                        }
                        m_compressor->close();
                        m_promise.set_value(true);
                    } catch (...) {
                        m_promise.set_exception(std::current_exception());
                        m_queue.drain();
                    }
                }
	Impl(GeneratorHandler &handler, const QString &fileName)
		: m_handler(handler)
		, m_outp(fileName.toStdString())
		, m_thread(&Impl::ThreadFunction, this)
	{
		if (!m_outp.is_open())
			throw std::invalid_argument("Cannot write to " + fileName.toStdString());

		auto threadStartWaiter = m_promice.get_future();
		threadStartWaiter.get();
	}
 FM<T>& set(SM<T, Ts...>& input, const bool is_lazy, Ts&... args) {
     _promise = std::promise<T>();
     _future = _promise.get_future();
     auto f = std::async(
         is_lazy ? std::launch::deferred : std::launch::async,
         [&] () {
             task_loop<T, Ts...>()(input, _promise, args...);
         }
     );
     if(is_lazy) f.get();
     return *this;
 };
Exemple #12
0
void live_cache::run(std::promise<void> promise) {
#ifndef MINGW32
	for (auto& url : m_urls) {
		auto sock = std::unique_ptr<zmq::socket_t>(new zmq::socket_t(*m_context, ZMQ_SUB));
		sock->setsockopt(ZMQ_SUBSCRIBE, "", 0);

		int zero = 0;
		sock->setsockopt(ZMQ_LINGER, &zero, sizeof(zero));

		sock->connect(url.c_str());

		m_socks.push_back(std::move(sock));
	}

	std::vector<zmq::pollitem_t> polls;

	for (auto& sock : m_socks) {
		zmq::pollitem_t poll;
		poll.socket = static_cast<void *>(*sock);	//It's the only way to handle this because of poor library API
		poll.events = ZMQ_POLLIN;

		polls.push_back(poll);
	}

	for (size_t i = 0; i < polls.size(); i++) 
		process_socket(i);

	promise.set_value();

	zmq::pollitem_t poll;
	poll.socket = nullptr;
	poll.fd = m_cmd_sock[0];
	poll.events = ZMQ_POLLIN;
	polls.push_back(poll);

	do {
		int rc = zmq::poll(&polls[0], polls.size(), -1);
		if (rc == -1)
			continue;

		for (size_t i = 0; i < polls.size() - 1; i++) 
			if (polls[i].revents & ZMQ_POLLIN)
				process_socket(i);

		if (polls.back().revents & ZMQ_POLLIN)
			return;
	} while (true);
#endif
}
void correlation_parallel_helper(VD::const_iterator first,
    VD::const_iterator last,
    std::promise<corr_intermediate> accumulate_promise)
{
    const size_t N = last - first;
    corr_intermediate result;
    result.sum = std::accumulate(first, last, 0);
    result.mean = result.sum / N;
    result.sumsqr = std::inner_product(first, last, first, 0);
    result.stdev = N > 1 ? sqrt((result.sumsqr - result.sum * result.sum / N) / (N - 1)) : 0;
    if (result.stdev) {
        result.Y.reserve(N);
        std::transform(first, last, result.Y.begin(), [result](double val) { return (val - result.mean)/result.stdev; });
    }
    accumulate_promise.set_value(result); // Notify future
}
Exemple #14
0
bool backtrackSolve(bool (*board)[8][8], unsigned short vPos, std::promise<bool>& p)
{
	if(vPos == 8) // catch for already complete board
		return true;
	for(unsigned short hPos = 0; hPos < 8; hPos++)
		if(singleConflictCheck(board, hPos, vPos))
		{
			(*board)[hPos][vPos] = 1;
			if(backtrackSolve(board, vPos + 1, p) == true) //return chain to escape all recursively called functions.
			{
				if(vPos == 0) //only run on initial function call
					p.set_value_at_thread_exit(true); //setting thread complete status on thread exit
				return true;
			}
			(*board)[hPos][vPos] = 0;
		}
	return false;
}
Exemple #15
0
void func5(std::promise<void> p)
{
    std::this_thread::sleep_for(ms(500));
    p.set_value();
}
inline void ExecuteAndSetValue<void>(std::function<void()> const& function,
                                     std::promise<void>& promise) {
  function();
  promise.set_value();
}
void ExecuteAndSetValue(std::function<T()> const& function,
                        std::promise<T>& promise) {
  promise.set_value(function());
}
Exemple #18
0
void func3(std::promise<int&> p)
{
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    j = 5;
    p.set_value(j);
}
Exemple #19
0
	/**
	*	@brief	Resets fence to unsignaled state
	*			Not thread-safe.
	*/
	void reset() override {
		f.reset();
		promise = std::promise<R>();
		future = promise.get_future().share();
	}
Exemple #20
0
void func4(std::promise<int&> p)
{
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    p.set_exception(std::make_exception_ptr(3.5));
}
Exemple #21
0
void func5(std::promise<void> p)
{
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    p.set_value();
}
Exemple #22
0
void func6(std::promise<void> p)
{
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    p.set_exception(std::make_exception_ptr('c'));
}
Exemple #23
0
	/**
	*	@brief	Signals the fence
	*
	*	@param	e		Exception to set the fence to
	*/
	void set_exception(const std::exception_ptr &e) {
		promise.set_exception(e);
	}
Exemple #24
0
 void set_value(std::promise<Fut>& p, F& f, T& t) {
    p.set_value(f(t));
 }
    dbusConnection_->disconnect();

    interfaceHandlerDBusConnection->unregisterObjectPath(objectPath);

    ASSERT_TRUE(interfaceHandlerDBusConnection->releaseServiceName(busName));
    interfaceHandlerDBusConnection->disconnect();
}

void dispatch(::DBusConnection* libdbusConnection) {
    dbus_bool_t success = TRUE;
    while (success) {
        success = dbus_connection_read_write_dispatch(libdbusConnection, 1);
    }
}

std::promise<bool> promise;
std::future<bool> future = promise.get_future();

void notifyThunk(DBusPendingCall*, void* data) {
    ::DBusConnection* libdbusConnection = reinterpret_cast<DBusConnection*>(data);
    dbus_connection_close(libdbusConnection);
    dbus_connection_unref(libdbusConnection);
    promise.set_value(true);
}

TEST_F(DBusConnectionTest, LibdbusConnectionsMayCommitSuicide) {
    const ::DBusBusType libdbusType = ::DBusBusType::DBUS_BUS_SESSION;
    ::DBusError libdbusError;
    dbus_error_init(&libdbusError);
    ::DBusConnection* libdbusConnection = dbus_bus_get_private(libdbusType, &libdbusError);
Exemple #26
0
void func(std::promise<int>& p)
{
    const int i = 5;
    p.set_value_at_thread_exit(i);
}
void notifyThunk(DBusPendingCall*, void* data) {
    ::DBusConnection* libdbusConnection = reinterpret_cast<DBusConnection*>(data);
    dbus_connection_close(libdbusConnection);
    dbus_connection_unref(libdbusConnection);
    promise.set_value(true);
}
Exemple #28
0
	void signal(T &&val,
				typename std::enable_if<!std::is_void<S>::value>::type* = nullptr) {
		promise.set_value(std::forward<T>(val));
	}
Exemple #29
0
 void set_value(std::promise<void>& p, F& f, T& t) {
    f(t);
    p.set_value();
 }
Exemple #30
0
	void signal(typename std::enable_if<std::is_void<S>::value>::type* = nullptr) {
		promise.set_value();
	}