• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ promise函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _model_info_ctor

/*! \brief  Creates and initialises a model info object.
 *
 *  \return  A valid model info object or \c NULL if unable to acquire
 *           the necessary memory resources.
 */
static _model_info_t *
_model_info_ctor (const char *fw_name, SANE_Status *status)
{
  SANE_Status s = SANE_STATUS_GOOD;
  _model_info_t *self = NULL;

  log_call ("(%s)", fw_name);
  require (fw_name);

  self = t_calloc (1, _model_info_t);
  if (!self)
    {
      if (status) *status = SANE_STATUS_NO_MEM;
      return NULL;
    }

  self->fw_name = strdup (fw_name);
  if (!self->fw_name)
    {
      _model_info_dtor (self);
      if (status) *status = SANE_STATUS_NO_MEM;
      return NULL;
    }

  /*  Set defaults using data defined in the source code.  The various
   *  getters decide a decent default in case self->fw_name is not one
   *  of the names for which we have data in our sources.
   */
  self->overseas = get_scanner_data (self->fw_name, MODEL_OVERSEAS);
  self->japan    = get_scanner_data (self->fw_name, MODEL_JAPAN);
  self->profile  = get_epson_scan_hard (self->fw_name);
  self->command  = get_scan_command (self->fw_name);

  self->from_file = false;

  s = _model_info_merge_file (self);

  self->name = _model_info_guess_name (self);

  if (self)                     /* make sure things are compliant */
    {
      promise (self->fw_name && self->name);
      promise (   self->name == self->fw_name
               || self->name == self->overseas
               || self->name == self->japan);
      promise (self->profile);
      promise (self->command);
    }
  if (status) *status = s;
  return self;
}
开发者ID:hean01,项目名称:iscan,代码行数:56,代码来源:model-info.c


示例2: cql_too_many_connections_per_host_exception

boost::shared_ptr<cql::cql_connection_t>
cql::cql_session_impl_t::allocate_connection(
    const boost::shared_ptr<cql_host_t>& host)
{
    if (!increase_connection_counter(host)) {
        throw cql_too_many_connections_per_host_exception();
    }

    boost::shared_ptr<cql_promise_t<cql_future_connection_t> > promise(
        new cql_promise_t<cql_future_connection_t>());

    boost::shared_ptr<cql_connection_t> connection(_client_callback());

    connection->set_credentials(_configuration->credentials());
    connection->connect(host->endpoint(),
                        boost::bind(&cql_session_impl_t::connect_callback, this->shared_from_this(), promise, ::_1),
                        boost::bind(&cql_session_impl_t::connect_errback,  this->shared_from_this(), promise, ::_1, ::_2));
    connection->set_keyspace(_keyspace_name);

    boost::shared_future<cql_future_connection_t> shared_future = promise->shared_future();
    shared_future.wait();

    if (shared_future.get().error.is_err()) {
        decrease_connection_counter(host);
        throw cql_connection_allocation_error(
                ("Error when connecting to host: " + host->endpoint().to_string()).c_str());
        connection.reset();
    }

    return connection;
}
开发者ID:benelgiac,项目名称:cpp-driver,代码行数:31,代码来源:cql_session_impl.cpp


示例3: promise

  qi::FutureSync<void> Session::waitForService(const std::string& servicename)
  {
    boost::shared_ptr<qi::Atomic<int> > link =
      boost::make_shared<qi::Atomic<int> >(0);

    qi::Promise<void> promise(qi::bindWithFallback<void(qi::Promise<void>)>(
          boost::function<void()>(),
          &SessionPrivate::onServiceTrackingCancelled,
          boost::weak_ptr<SessionPrivate>(_p),
          _1,
          link));
    *link = (int)_p->_sdClient.serviceAdded.connect(
          &SessionPrivate::onTrackedServiceAdded,
          boost::weak_ptr<SessionPrivate>(_p),
          _2,
          servicename,
          promise,
          link);

    qi::Future<qi::AnyObject> s = service(servicename);
    if (!s.hasError())
      // service is already available, trigger manually (it's ok if it's
      // triggered multiple time)
      _p->onTrackedServiceAdded(servicename, servicename, promise, link);

    return promise.future();
  }
开发者ID:bsautron,项目名称:libqi,代码行数:27,代码来源:session.cpp


示例4: EME_LOG

void
MediaKeys::ResolvePromise(PromiseId aId)
{
  EME_LOG("MediaKeys[%p]::ResolvePromise(%d)", this, aId);

  RefPtr<DetailedPromise> promise(RetrievePromise(aId));
  if (!promise) {
    return;
  }
  if (mPendingSessions.Contains(aId)) {
    // We should only resolve LoadSession calls via this path,
    // not CreateSession() promises.
    RefPtr<MediaKeySession> session;
    if (!mPendingSessions.Get(aId, getter_AddRefs(session)) ||
        !session ||
        session->GetSessionId().IsEmpty()) {
      NS_WARNING("Received activation for non-existent session!");
      promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR,
                           NS_LITERAL_CSTRING("CDM LoadSession() returned a different session ID than requested"));
      mPendingSessions.Remove(aId);
      return;
    }
    mPendingSessions.Remove(aId);
    mKeySessions.Put(session->GetSessionId(), session);
    promise->MaybeResolve(session);
  } else {
    promise->MaybeResolve(JS::UndefinedHandleValue);
  }
  MOZ_ASSERT(!mPromises.Contains(aId));
}
开发者ID:bolt-dev,项目名称:gecko-dev,代码行数:30,代码来源:MediaKeys.cpp


示例5: promise

void
MediaKeys::OnCDMCreated(PromiseId aId, const nsACString& aNodeId, const uint32_t aPluginId)
{
  RefPtr<DetailedPromise> promise(RetrievePromise(aId));
  if (!promise) {
    return;
  }
  mNodeId = aNodeId;
  RefPtr<MediaKeys> keys(this);
  EME_LOG("MediaKeys[%p]::OnCDMCreated() resolve promise id=%d", this, aId);
  promise->MaybeResolve(keys);
  if (mCreatePromiseId == aId) {
    Release();
  }

  MediaKeySystemAccess::NotifyObservers(mParent,
                                        mKeySystem,
                                        MediaKeySystemStatus::Cdm_created);

  if (aPluginId) {
    // Prepare plugin crash reporter.
    RefPtr<gmp::GeckoMediaPluginService> service =
      gmp::GeckoMediaPluginService::GetGeckoMediaPluginService();
    if (NS_WARN_IF(!service)) {
      return;
    }
    if (NS_WARN_IF(!mParent)) {
      return;
    }
    service->AddPluginCrashedEventTarget(aPluginId, mParent);
    EME_LOG("MediaKeys[%p]::OnCDMCreated() registered crash handler for pluginId '%i'",
            this, aPluginId);
  }
}
开发者ID:bolt-dev,项目名称:gecko-dev,代码行数:34,代码来源:MediaKeys.cpp


示例6: promise

already_AddRefed<Promise>
MediaKeys::CreateSession(const nsAString& initDataType,
                         const Uint8Array& aInitData,
                         SessionType aSessionType,
                         ErrorResult& aRv)
{
  aInitData.ComputeLengthAndData();
  nsRefPtr<Promise> promise(MakePromise(aRv));
  if (aRv.Failed()) {
    return nullptr;
  }
  nsRefPtr<MediaKeySession> session = new MediaKeySession(GetParentObject(),
                                                          this,
                                                          mKeySystem,
                                                          aSessionType, aRv);
  if (aRv.Failed()) {
    return nullptr;
  }

  auto pid = StorePromise(promise);
  // Hang onto session until the CDM has finished setting it up.
  mPendingSessions.Put(pid, session);
  mProxy->CreateSession(aSessionType,
                        pid,
                        initDataType,
                        aInitData);

  return promise.forget();
}
开发者ID:andrenatal,项目名称:gecko-dev,代码行数:29,代码来源:MediaKeys.cpp


示例7: promise

already_AddRefed<Promise>
MediaKeySession::GetUsableKeyIds(ErrorResult& aRv)
{
  nsRefPtr<Promise> promise(mKeys->MakePromise(aRv));
  if (aRv.Failed()) {
    return nullptr;
  }

  if (IsClosed() || !mKeys->GetCDMProxy()) {
    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
    return promise.forget();
  }

  nsTArray<CencKeyId> keyIds;
  {
    CDMCaps::AutoLock caps(mKeys->GetCDMProxy()->Capabilites());
    caps.GetUsableKeysForSession(mSessionId, keyIds);
  }

  nsTArray<TypedArrayCreator<ArrayBuffer>> array;
  for (size_t i = 0; i < keyIds.Length(); i++) {
    array.AppendElement(keyIds[i]);
  }
  promise->MaybeResolve(array);

  return promise.forget();
}
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:27,代码来源:MediaKeySession.cpp


示例8: promise

already_AddRefed<Promise>
MediaKeySession::Remove(ErrorResult& aRv)
{
  nsRefPtr<DetailedPromise> promise(MakePromise(aRv,
    NS_LITERAL_CSTRING("MediaKeySession.remove")));
  if (aRv.Failed()) {
    return nullptr;
  }
  if (mSessionType != SessionType::Persistent) {
    promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR,
                         NS_LITERAL_CSTRING("Calling MediaKeySession.remove() on non-persistent session"));
    // "The operation is not supported on session type sessions."
    EME_LOG("MediaKeySession[%p,'%s'] Remove() failed, sesion not persisrtent.",
            this, NS_ConvertUTF16toUTF8(mSessionId).get());
    return promise.forget();
  }
  if (IsClosed() || !mKeys->GetCDMProxy()) {
    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
                         NS_LITERAL_CSTRING("MediaKeySesison.remove() called but session is not active"));
    // "The session is closed."
    EME_LOG("MediaKeySession[%p,'%s'] Remove() failed, already session closed.",
            this, NS_ConvertUTF16toUTF8(mSessionId).get());
    return promise.forget();
  }
  PromiseId pid = mKeys->StorePromise(promise);
  mKeys->GetCDMProxy()->RemoveSession(mSessionId, pid);
  EME_LOG("MediaKeySession[%p,'%s'] Remove() sent to CDM, promiseId=%d.",
          this, NS_ConvertUTF16toUTF8(mSessionId).get(), pid);

  return promise.forget();
}
开发者ID:rhelmer,项目名称:gecko-dev,代码行数:31,代码来源:MediaKeySession.cpp


示例9: promise

void
MediaKeys::ResolvePromise(PromiseId aId)
{
  nsRefPtr<Promise> promise(RetrievePromise(aId));
  if (!promise) {
    NS_WARNING("MediaKeys tried to resolve a non-existent promise");
    return;
  }
  if (mPendingSessions.Contains(aId)) {
    // We should only resolve LoadSession calls via this path,
    // not CreateSession() promises.
    nsRefPtr<MediaKeySession> session;
    if (!mPendingSessions.Get(aId, getter_AddRefs(session)) ||
        !session ||
        session->GetSessionId().IsEmpty()) {
      NS_WARNING("Received activation for non-existent session!");
      promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
      mPendingSessions.Remove(aId);
      return;
    }
    mPendingSessions.Remove(aId);
    mKeySessions.Put(session->GetSessionId(), session);
    promise->MaybeResolve(session);
  } else {
    promise->MaybeResolve(JS::UndefinedHandleValue);
  }
}
开发者ID:fatman2021,项目名称:gecko-dev,代码行数:27,代码来源:MediaKeys.cpp


示例10: promise

already_AddRefed<Promise>
MediaKeySession::Close(ErrorResult& aRv)
{
  RefPtr<DetailedPromise> promise(MakePromise(aRv,
    NS_LITERAL_CSTRING("MediaKeySession.close")));
  if (aRv.Failed()) {
    return nullptr;
  }
  if (!IsCallable()) {
    // If this object's callable value is false, return a promise rejected
    // with a new DOMException whose name is InvalidStateError.
    EME_LOG("MediaKeySession[%p,''] Close() called before sessionId set by CDM", this);
    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
      NS_LITERAL_CSTRING("MediaKeySession.Close() called before sessionId set by CDM"));
    return promise.forget();
  }
  if (IsClosed() || !mKeys->GetCDMProxy()) {
    EME_LOG("MediaKeySession[%p,'%s'] Close() already closed",
            this, NS_ConvertUTF16toUTF8(mSessionId).get());
    promise->MaybeResolve(JS::UndefinedHandleValue);
    return promise.forget();
  }
  PromiseId pid = mKeys->StorePromise(promise);
  mKeys->GetCDMProxy()->CloseSession(mSessionId, pid);

  EME_LOG("MediaKeySession[%p,'%s'] Close() sent to CDM, promiseId=%d",
          this, NS_ConvertUTF16toUTF8(mSessionId).get(), pid);

  return promise.forget();
}
开发者ID:cliqz-oss,项目名称:browser-f,代码行数:30,代码来源:MediaKeySession.cpp


示例11: TEST_F

TEST_F(ScriptPromiseTest, constructFromNonPromise)
{
    v8::TryCatch trycatch;
    ScriptPromise promise(scriptState(), v8::Undefined(isolate()));
    ASSERT_TRUE(trycatch.HasCaught());
    ASSERT_TRUE(promise.isEmpty());
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:7,代码来源:ScriptPromiseTest.cpp


示例12: promise

already_AddRefed<Promise>
MediaKeySession::Load(const nsAString& aSessionId, ErrorResult& aRv)
{
    nsRefPtr<Promise> promise(mKeys->MakePromise(aRv));
    if (aRv.Failed()) {
        return nullptr;
    }

    if (aSessionId.IsEmpty()) {
        promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
        // "The sessionId parameter is empty."
        return promise.forget();
    }

    if (!mUninitialized) {
        promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
        return promise.forget();
    }

    mUninitialized = false;

    // We now know the sessionId being loaded into this session. Remove the
    // session from its owning MediaKey's set of sessions awaiting a sessionId.
    nsRefPtr<MediaKeySession> session(mKeys->GetPendingSession(Token()));
    MOZ_ASSERT(session == this, "Session should be awaiting id on its own token");

    // Associate with the known sessionId.
    SetSessionId(aSessionId);

    mKeys->GetCDMProxy()->LoadSession(mKeys->StorePromise(promise), aSessionId);

    return promise.forget();
}
开发者ID:Acidburn0zzz,项目名称:tor-browser,代码行数:33,代码来源:MediaKeySession.cpp


示例13: promise

already_AddRefed<Promise>
MediaKeySession::GenerateRequest(const nsAString& aInitDataType,
                                 const ArrayBufferViewOrArrayBuffer& aInitData,
                                 ErrorResult& aRv)
{
  RefPtr<DetailedPromise> promise(MakePromise(aRv,
    NS_LITERAL_CSTRING("MediaKeySession.generateRequest")));
  if (aRv.Failed()) {
    return nullptr;
  }

  if (!mUninitialized) {
    EME_LOG("MediaKeySession[%p,'%s'] GenerateRequest() failed, uninitialized",
            this, NS_ConvertUTF16toUTF8(mSessionId).get());
    promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR,
      NS_LITERAL_CSTRING("Session is already initialized in MediaKeySession.generateRequest()"));
    return promise.forget();
  }

  mUninitialized = false;

  if (aInitDataType.IsEmpty()) {
    promise->MaybeReject(NS_ERROR_DOM_TYPE_ERR,
      NS_LITERAL_CSTRING("Empty initDataType passed to MediaKeySession.generateRequest()"));
    EME_LOG("MediaKeySession[%p,'%s'] GenerateRequest() failed, empty initDataType",
      this, NS_ConvertUTF16toUTF8(mSessionId).get());
    return promise.forget();
  }

  nsTArray<uint8_t> data;
  CopyArrayBufferViewOrArrayBufferData(aInitData, data);
  if (data.IsEmpty()) {
    promise->MaybeReject(NS_ERROR_DOM_TYPE_ERR,
      NS_LITERAL_CSTRING("Empty initData passed to MediaKeySession.generateRequest()"));
    EME_LOG("MediaKeySession[%p,'%s'] GenerateRequest() failed, empty initData",
      this, NS_ConvertUTF16toUTF8(mSessionId).get());
    return promise.forget();
  }

  // Convert initData to base64 for easier logging.
  // Note: CreateSession() Move()s the data out of the array, so we have
  // to copy it here.
  nsAutoCString base64InitData(ToBase64(data));
  PromiseId pid = mKeys->StorePromise(promise);
  mKeys->GetCDMProxy()->CreateSession(Token(),
                                      mSessionType,
                                      pid,
                                      aInitDataType, data);

  EME_LOG("MediaKeySession[%p,'%s'] GenerateRequest() sent, "
          "promiseId=%d initData(base64)='%s' initDataType='%s'",
          this,
          NS_ConvertUTF16toUTF8(mSessionId).get(),
          pid,
          base64InitData.get(),
          NS_ConvertUTF16toUTF8(aInitDataType).get());

  return promise.forget();
}
开发者ID:Danielzac,项目名称:gecko-dev,代码行数:59,代码来源:MediaKeySession.cpp


示例14: promise

void Z3STRConstraintWriter::visit(Symbolic::StringCoercion* stringcoercion, void* args)
{
    CoercionPromise promise(Symbolic::STRING);
    stringcoercion->getExpression()->accept(this);

    if (!promise.isCoerced) {
        coercetype(mExpressionType, Symbolic::STRING, mExpressionBuffer); // Sets mExpressionBuffer and Type.
    }
}
开发者ID:mrgenco,项目名称:Artemis,代码行数:9,代码来源:z3str.cpp


示例15: promise

void SMTConstraintWriter::visit(Symbolic::BooleanCoercion* booleancoercion, void* args)
{
    CoercionPromise promise(Symbolic::BOOL);
    booleancoercion->getExpression()->accept(this);

    if (!promise.isCoerced) {
        coercetype(mExpressionType, Symbolic::BOOL, mExpressionBuffer); // Sets mExpressionBuffer and Type.
    }
}
开发者ID:mrgenco,项目名称:Artemis,代码行数:9,代码来源:smt.cpp


示例16: promise

VoidFuture TaskDispatcherBase::stop() {
	std::shared_ptr<VoidPromise> promise(new VoidPromise());
	std::lock_guard<std::mutex> l(*this);
	mAcceptTasks = false;
	mQeuedTasks.push_back([promise, this]() {
						  abort();
						  promise->set_value(); }); 
	activateProcessing();
	return promise->get_future();
}
开发者ID:helgebetzinger,项目名称:coasync4cpp,代码行数:10,代码来源:TaskDispatcher.cpp


示例17: job

RefPtr<CDMProxy::DecryptPromise>
CDMProxy::Decrypt(MediaRawData* aSample)
{
  RefPtr<DecryptJob> job(new DecryptJob(aSample));
  RefPtr<DecryptPromise> promise(job->Ensure());

  nsCOMPtr<nsIRunnable> task(
    NewRunnableMethod<RefPtr<DecryptJob>>(this, &CDMProxy::gmp_Decrypt, job));
  mGMPThread->Dispatch(task, NS_DISPATCH_NORMAL);
  return promise;
}
开发者ID:NAndreasson,项目名称:cowl-patches,代码行数:11,代码来源:CDMProxy.cpp


示例18: strlen

// Optimized for repeating calls
char *typestr::append_char(char c)
{
    size_t existing_len = m_str ? strlen(m_str) : 0;
    size_t needed = existing_len + 1 + 1;
    if (m_size < needed)
    {
        needed += 100;
        promise(needed);
    }
    m_str[existing_len] = c;
    m_str[existing_len + 1] = '\0';
    return m_str;
}
开发者ID:NatLibFi,项目名称:usemarcon,代码行数:14,代码来源:typedef.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ promote函数代码示例发布时间:2022-05-30
下一篇:
C++ prom_searchsiblings函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap