promise-cpp应用--01简单应用

promise-cpp是一种 C++ promise/A+ 库


#include <iostream>
#include <future>
#include <string>
#include <sstream>
#include <stdexcept>
#include <functional>
#include <locale>
#include <codecvt>
//
#ifndef  PROMISE_HEADONLY
  #define  PROMISE_HEADONLY
#endif
#include "promise-cpp/promise.hpp"
//

------------------------------

//--------------------------------------------------------------------------------------------

static promise::Promise testPromise()
{

  return promise::newPromise([&](promise::Defer &defer)
                             {
                               //
                               defer.resolve(9567, 'A');
                               //
                             })
      .then(                  //
          [&](int n, char ch) // function on_resolved
          {
            //
            printf("%d %c\n", n, ch); // will print 9567 here
                                      //
          },                          //
          []()                        // function on_rejected
          {
            //
            printf("promise rejected\n");
            // will not run to here in this code
          });
}

------------------------------

void PromiseCommand::OnClick()
{
  //
  testPromise();
}
posted @ 2023-01-17 11:08  ParamousGIS  阅读(37)  评论(0编辑  收藏  举报