Skip to content

Commit b49212a

Browse files
committed
Restore test for unzip
Signed-off-by: Michael X. Grey <grey@openrobotics.org>
1 parent 5016025 commit b49212a

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

src/chain.rs

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
420420
/// `unzip_build` allows you to split it into multiple chains (one for each
421421
/// tuple element) and apply a separate builder function to each chain. You
422422
/// will be passed back the zipped output of all the builder functions.
423-
#[must_use]
424423
pub fn unzip_build<Build>(self, build: Build) -> Build::ReturnType
425424
where
426425
Build: UnzipBuilder<T>
@@ -795,41 +794,50 @@ mod tests {
795794
assert!(context.no_unhandled_errors());
796795
}
797796

798-
// #[test]
799-
// fn test_unzip() {
800-
// let mut context = TestingContext::minimal_plugins();
797+
#[test]
798+
fn test_unzip() {
799+
let mut context = TestingContext::minimal_plugins();
801800

802-
// let mut promise = context.build(|commands| {
803-
// commands
804-
// .request((2.0, 3.0), add.into_blocking_map())
805-
// .map_block(|v| (v, 2.0*v))
806-
// .unzip_build((
807-
// |chain: Chain<f64>| {
808-
// chain
809-
// .map_block(|v| (v, 10.0))
810-
// .map_block(add)
811-
// .dangle()
812-
// },
813-
// |chain: Chain<f64>| {
814-
// chain
815-
// .map_block(|value|
816-
// WaitRequest{
817-
// duration: std::time::Duration::from_secs_f64(0.01),
818-
// value,
819-
// }
820-
// )
821-
// .map_async(wait)
822-
// .dangle()
823-
// }
824-
// ))
825-
// .bundle()
826-
// .race_bundle(commands)
827-
// .take()
828-
// });
801+
let workflow = context.build_io_workflow(|scope, builder| {
802+
scope.input.chain(builder)
803+
.map_block(add)
804+
.map_block(|v| (v, 2.0*v))
805+
.then_scope::<_, ()>(ScopeSettings::default(), |scope, builder| {
806+
scope.input.chain(builder)
807+
.unzip_build((
808+
|chain: Chain<f64>| {
809+
chain
810+
.map_block(|v| (v, 10.0))
811+
.map_block(add)
812+
.connect(scope.terminate);
813+
},
814+
|chain: Chain<f64>| {
815+
chain
816+
.map_block(|value|
817+
WaitRequest{
818+
duration: std::time::Duration::from_secs_f64(0.01),
819+
value,
820+
}
821+
)
822+
.map_async(wait)
823+
.connect(scope.terminate);
824+
},
825+
));
826+
})
827+
.connect(scope.terminate);
828+
});
829829

830-
// context.run_while_pending(&mut promise);
831-
// assert_eq!(promise.peek().available().copied(), Some(15.0));
832-
// }
830+
831+
let mut promise = context.build(|commands| {
832+
commands
833+
.request((2.0, 3.0), workflow)
834+
.take_response()
835+
});
836+
837+
context.run_while_pending(&mut promise);
838+
assert_eq!(promise.peek().available().copied(), Some(15.0));
839+
assert!(context.no_unhandled_errors());
840+
}
833841

834842
// #[test]
835843
// fn test_dispose_on_cancel() {

0 commit comments

Comments
 (0)