Skip to content

Instantly share code, notes, and snippets.

@jnicholls
Created May 20, 2015 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnicholls/aaa0652673439b3d0603 to your computer and use it in GitHub Desktop.
Save jnicholls/aaa0652673439b3d0603 to your computer and use it in GitHub Desktop.
for x in 0..10 {
let promise = Promise::<u32,&str>::new(move || {
match x {
0 => Err("Division by zero"),
_ => Ok(x * 2)
}
}).success(move |res| {
assert_eq!(res, x * 2);
Ok(res * 2)
}).success(|res| {
Ok(format!("{}", res))
}).fail(|error| {
assert_eq!(error, "Division by zero");
Err(error)
}) ;
let result = promise.sync();
match x {
0 => assert!(result.is_err()),
_ => {
assert!(result.is_ok());
assert_eq!(result.unwrap(), format!("{}", x * 4));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment