Last active
June 19, 2018 15:00
-
-
Save autodidaddict/33ce20152d57a8721102fedf90ae8103 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn get_library_entries( | |
&self, | |
ctx: RpcContext, | |
req: LibraryEntriesRequest, | |
resp: ServerStreamingSink<LibraryEntry>, | |
) { | |
info!( | |
"Handling get library entries request: {}", | |
req.get_agent_id() | |
); | |
match self.data_store.get_owned_entries(req.get_agent_id()) { | |
Ok(raw_entries) => { | |
let out: Vec<(LibraryEntry, WriteFlags)> = raw_entries.into_iter().map(|entry| { | |
(entry.into(), WriteFlags::default()) | |
}) | |
.collect(); | |
let f = resp.send_all(stream::iter_ok::<_, Error>(out)).map(|_|()); | |
ctx.spawn(f.map_err(|e| error!("Failed to handle get library entries: {:?}", e))); | |
}, | |
Err(_) => { | |
let f = resp.fail(RpcStatus::new(RpcStatusCode::Internal, None)); | |
ctx.spawn(f.map_err(|e| error!("Failed to handle get library entries: {:?}", e))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, I don't think we can turn it into a single Future because we can't move sink into two different closures.
What I ended up doing for my toy example was this
It is logically the same as your code and stinks of golang. shrug