当前位置: 首页>>代码示例>>C++>>正文


C++ std::promise类代码示例

本文整理汇总了C++中std::promise的典型用法代码示例。如果您正苦于以下问题:C++ promise类的具体用法?C++ promise怎么用?C++ promise使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了promise类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: finish

    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();
    }
开发者ID:Kosta-Github,项目名称:http-cpp,代码行数:27,代码来源:client.cpp

示例2: op

 void op()  // GB was operator
 {
     try {
         promise.set_value(f());
     } catch(...) {
         promise.set_exception(std::current_exception());
     }
 }
开发者ID:sarout,项目名称:SenecaOOP345-attic,代码行数:8,代码来源:f-pt.cpp

示例3: f

	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));
	}
开发者ID:ssteinberg,项目名称:ste,代码行数:11,代码来源:shared_fence.hpp

示例4: doSomething

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
    }
}
开发者ID:CCJY,项目名称:coliru,代码行数:17,代码来源:main.cpp

示例5: operator

                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();
                    }
                }
开发者ID:7ute,项目名称:osrm-backend,代码行数:18,代码来源:write_thread.hpp

示例6: set

 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;
 };
开发者ID:diegoperini,项目名称:cppnow2014-doppl,代码行数:12,代码来源:doppl_future_member.hpp

示例7: correlation_parallel_helper

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
}
开发者ID:magland,项目名称:mountainlab,代码行数:16,代码来源:tst_mlcomputetest.cpp

示例8: backtrackSolve

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;
}
开发者ID:AV-IO,项目名称:8_Queens,代码行数:18,代码来源:Source.cpp

示例9: func5

void func5(std::promise<void> p)
{
    std::this_thread::sleep_for(ms(500));
    p.set_value();
}
开发者ID:99corps,项目名称:runtime,代码行数:5,代码来源:wait_until.pass.cpp

示例10: function

inline void ExecuteAndSetValue<void>(std::function<void()> const& function,
                                     std::promise<void>& promise) {
  function();
  promise.set_value();
}
开发者ID:mockingbirdnest,项目名称:Principia,代码行数:5,代码来源:thread_pool_body.hpp

示例11: ExecuteAndSetValue

void ExecuteAndSetValue(std::function<T()> const& function,
                        std::promise<T>& promise) {
  promise.set_value(function());
}
开发者ID:mockingbirdnest,项目名称:Principia,代码行数:4,代码来源:thread_pool_body.hpp

示例12: func3

void func3(std::promise<int&> p)
{
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    j = 5;
    p.set_value(j);
}
开发者ID:AstroVPK,项目名称:LLVM-4.0.0,代码行数:6,代码来源:get.pass.cpp

示例13: reset

	/**
	*	@brief	Resets fence to unsignaled state
	*			Not thread-safe.
	*/
	void reset() override {
		f.reset();
		promise = std::promise<R>();
		future = promise.get_future().share();
	}
开发者ID:ssteinberg,项目名称:ste,代码行数:9,代码来源:shared_fence.hpp

示例14: func4

void func4(std::promise<int&> p)
{
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    p.set_exception(std::make_exception_ptr(3.5));
}
开发者ID:AstroVPK,项目名称:LLVM-4.0.0,代码行数:5,代码来源:get.pass.cpp

示例15: func5

void func5(std::promise<void> p)
{
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    p.set_value();
}
开发者ID:AstroVPK,项目名称:LLVM-4.0.0,代码行数:5,代码来源:get.pass.cpp


注:本文中的std::promise类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。