From 400885e62088f5877ff1a9c5133034f3ebd91df8 Mon Sep 17 00:00:00 2001 From: Stefan Reiter Date: Mon, 7 Jun 2021 17:35:24 +0200 Subject: [PATCH] tools/BroadcastFuture: add testcase for better understanding Explicitly test that data will stay available and can be retrieved immediately via listen(), even if the future producing the data and notifying the consumers was already run in the past. Wasn't broken or anything, but helps with understanding IMO. Signed-off-by: Stefan Reiter --- src/tools/broadcast_future.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/tools/broadcast_future.rs b/src/tools/broadcast_future.rs index 88b7aaab..7bfd83b7 100644 --- a/src/tools/broadcast_future.rs +++ b/src/tools/broadcast_future.rs @@ -166,4 +166,15 @@ fn test_broadcast_future() { let result = CHECKSUM.load(Ordering::SeqCst); assert_eq!(result, 3); + + // the result stays available until the BroadcastFuture is dropped + rt.block_on(sender.listen() + .map_ok(|res| { + CHECKSUM.fetch_add(res*4, Ordering::SeqCst); + }) + .map_err(|err| { panic!("got error {}", err); }) + .map(|_| ())); + + let result = CHECKSUM.load(Ordering::SeqCst); + assert_eq!(result, 7); }