File tree Expand file tree Collapse file tree
include/launchdarkly/async Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -283,7 +283,9 @@ class Promise {
283283 Promise () : internal_(new PromiseInternal<T>()) {}
284284 ~Promise () = default ;
285285 Promise (Promise const &) = delete ;
286+ Promise& operator =(Promise const &) = delete ;
286287 Promise (Promise&&) = default ;
288+ Promise& operator =(Promise&&) = default ;
287289
288290 // Sets the result to the given value and schedules any continuations that
289291 // were registered via Future::Then. Returns true if the result was set, or
@@ -336,7 +338,9 @@ class Future {
336338 : internal_(internal) {}
337339 ~Future () = default ;
338340 Future (Future const &) = default ;
341+ Future& operator =(Future const &) = default ;
339342 Future (Future&&) = default ;
343+ Future& operator =(Future&&) = default ;
340344
341345 // Returns true if the associated Promise has been resolved.
342346 bool IsFinished () const { return internal_->IsFinished (); }
Original file line number Diff line number Diff line change @@ -307,6 +307,43 @@ TEST(Promise, ExpectedFailure) {
307307 EXPECT_EQ (result->error (), " timed out" );
308308}
309309
310+ // Verifies that Promise supports move assignment, consistent with it being
311+ // move-only.
312+ TEST (Promise, MoveAssignment) {
313+ Promise<int > p1;
314+ Future<int > future = p1.GetFuture ();
315+
316+ Promise<int > p2;
317+ p2 = std::move (p1);
318+ p2.Resolve (42 );
319+
320+ EXPECT_EQ (*future.GetResult (), 42 );
321+ }
322+
323+ // Verifies that Future supports move assignment.
324+ TEST (Promise, FutureMoveAssignment) {
325+ Promise<int > promise;
326+ Future<int > f1 = promise.GetFuture ();
327+ Future<int > f2 = promise.GetFuture ();
328+
329+ f2 = std::move (f1);
330+ promise.Resolve (42 );
331+
332+ EXPECT_EQ (*f2.GetResult (), 42 );
333+ }
334+
335+ // Verifies that Future supports copy assignment.
336+ TEST (Promise, FutureCopyAssignment) {
337+ Promise<int > promise;
338+ Future<int > f1 = promise.GetFuture ();
339+ Future<int > f2 = promise.GetFuture ();
340+
341+ f2 = f1;
342+ promise.Resolve (42 );
343+
344+ EXPECT_EQ (*f2.GetResult (), 42 );
345+ }
346+
310347// Verifies that a Continuation can be constructed from an lvalue callable
311348// (named lambda), not just from a temporary.
312349TEST (Promise, LvalueLambdaContinuation) {
You can’t perform that action at this time.
0 commit comments