ipc/ipdl/test/cxx/TestAsyncReturns.h
author Kan-Ru Chen <kanru@kanru.info>
Thu, 25 May 2017 21:25:52 -0400
changeset 361791 9a39e2222a478bb59bfbc1ee0d6d41adca1e392c
parent 353615 325bf1bf5a1fa2aa5c9169396305d85e8c17fcad
child 450554 09c71a7cf75aeaf2963050e315276fb9a866fd62
permissions -rw-r--r--
Bug 1368031 - Pass resolver function to Recv methods instead of a MozPromise r=billm Added new typedef for the Resolve function. The Resolve function is a std::function accepting corresponding parameters. When it's invoked it will send the reply immediately. Users can still wrap it in a MozPromise if they want promise chaining. The original typedef of the Promise type is repurposed as the Send* functions' return type. MozReview-Commit-ID: JZ4IsgJ87M1

#ifndef mozilla__ipdltest_TestAsyncReturns_h
#define mozilla__ipdltest_TestAsyncReturns_h 1

#include "mozilla/_ipdltest/IPDLUnitTests.h"

#include "mozilla/_ipdltest/PTestAsyncReturnsParent.h"
#include "mozilla/_ipdltest/PTestAsyncReturnsChild.h"

namespace mozilla {
namespace _ipdltest {


class TestAsyncReturnsParent :
    public PTestAsyncReturnsParent
{
public:
  TestAsyncReturnsParent();
  virtual ~TestAsyncReturnsParent();

  static bool RunTestInProcesses() { return true; }
  static bool RunTestInThreads() { return true; }

  void Main();

protected:
  mozilla::ipc::IPCResult RecvPong(PongResolver&& aResolve) override;

  virtual void ActorDestroy(ActorDestroyReason why) override
  {
    if (NormalShutdown != why)
      fail("unexpected destruction!");
    passed("ok");
    QuitParent();
  }
};


class TestAsyncReturnsChild :
    public PTestAsyncReturnsChild
{
public:
  TestAsyncReturnsChild();
  virtual ~TestAsyncReturnsChild();

protected:
  mozilla::ipc::IPCResult RecvPing(PingResolver&& aResolve) override;
  mozilla::ipc::IPCResult RecvNoReturn(NoReturnResolver&& aResolve) override;

  virtual void ActorDestroy(ActorDestroyReason why) override
  {
    if (NormalShutdown != why)
      fail("unexpected destruction!");
    QuitChild();
  }
};


} // namespace _ipdltest
} // namespace mozilla


#endif // ifndef mozilla__ipdltest_TestAsyncReturns_h