Beispiel #1
0
 void op()  // GB was operator
 {
     try {
         promise.set_value(f());
     } catch(...) {
         promise.set_exception(std::current_exception());
     }
 }
Beispiel #2
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
    }
}
Beispiel #3
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();
                    }
                }
Beispiel #4
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);
	}
Beispiel #5
0
void func6(std::promise<void> p)
{
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    p.set_exception(std::make_exception_ptr('c'));
}
Beispiel #6
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));
}