proxygen
SelfDestructTest.cpp File Reference

Go to the source code of this file.

Classes

class  ThrowingExecutorError
 
class  ThrowingExecutor
 

Functions

 TEST (SelfDestruct, then)
 
 TEST (SelfDestruct, ensure)
 
 TEST (SelfDestruct, throwingExecutor)
 
 TEST (SelfDestruct, throwingInlineExecutor)
 

Function Documentation

TEST ( SelfDestruct  ,
then   
)

Definition at line 23 of file SelfDestructTest.cpp.

References EXPECT_EQ, folly::Promise< T >::getFuture(), and folly::gen::move.

23  {
24  auto* p = new Promise<int>();
25  auto future = p->getFuture().then([p](int x) {
26  delete p;
27  return x + 1;
28  });
29  p->setValue(123);
30  EXPECT_EQ(124, std::move(future).get());
31 }
Definition: InvokeTest.cpp:58
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Future< T > getFuture()
Definition: Promise-inl.h:97
TEST ( SelfDestruct  ,
ensure   
)

Definition at line 33 of file SelfDestructTest.cpp.

References EXPECT_EQ, folly::Promise< T >::getFuture(), and folly::gen::move.

33  {
34  auto* p = new Promise<int>();
35  auto future = p->getFuture().ensure([p] { delete p; });
36  p->setValue(123);
37  EXPECT_EQ(123, std::move(future).get());
38 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Future< T > getFuture()
Definition: Promise-inl.h:97
TEST ( SelfDestruct  ,
throwingExecutor   
)

Definition at line 52 of file SelfDestructTest.cpp.

References folly::pushmi::executor, EXPECT_EQ, folly::Promise< T >::getFuture(), and folly::gen::move.

52  {
54  auto* p = new Promise<int>();
55  auto future =
56  p->getFuture().via(&executor).onError([p](ThrowingExecutorError const&) {
57  delete p;
58  return 456;
59  });
60  p->setValue(123);
61  EXPECT_EQ(456, std::move(future).get());
62 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
Future< T > getFuture()
Definition: Promise-inl.h:97
TEST ( SelfDestruct  ,
throwingInlineExecutor   
)

Definition at line 64 of file SelfDestructTest.cpp.

References folly::pushmi::executor, EXPECT_EQ, folly::Promise< T >::getFuture(), and folly::gen::move.

64  {
66 
67  auto* p = new Promise<int>();
68  auto future = p->getFuture()
69  .via(&executor)
70  .thenValue([p](auto &&) -> int {
71  delete p;
72  throw ThrowingExecutorError("callback throws");
73  })
74  .onError([](ThrowingExecutorError const&) { return 456; });
75  p->setValue(123);
76  EXPECT_EQ(456, std::move(future).get());
77 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
Future< T > getFuture()
Definition: Promise-inl.h:97