Skip to content

Commit

Permalink
Implemented iterator() method on returned remote stream to consume st…
Browse files Browse the repository at this point in the history
…ream for only Null terminated traversals
  • Loading branch information
criminosis committed Sep 17, 2024
1 parent 6a94a88 commit bce3737
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
12 changes: 12 additions & 0 deletions gremlin-client/src/aio/process/traversal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::GremlinResult;
use core::task::Context;
use core::task::Poll;
use futures::Stream;
use futures::StreamExt;
use std::marker::PhantomData;
use std::pin::Pin;

Expand All @@ -29,6 +30,17 @@ impl<T> RemoteTraversalStream<T> {
}
}
}

impl RemoteTraversalStream<crate::structure::Null> {
pub async fn iterate(&mut self) -> GremlinResult<()> {
while let Some(response) = self.next().await {
//consume the entire stream, returning any errors
response?;
}
Ok(())
}
}

impl<T: FromGValue> Stream for RemoteTraversalStream<T> {
type Item = GremlinResult<T>;

Expand Down
10 changes: 10 additions & 0 deletions gremlin-client/src/process/traversal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ impl<T: FromGValue> RemoteTraversalIterator<T> {
}
}

impl RemoteTraversalIterator<crate::structure::Null> {
pub fn iterate(&mut self) -> GremlinResult<()> {
while let Some(response) = self.next() {
//consume the entire iterator, returning any errors
response?;
}
Ok(())
}
}

impl<T: FromGValue> Iterator for RemoteTraversalIterator<T> {
type Item = GremlinResult<T>;

Expand Down
11 changes: 4 additions & 7 deletions gremlin-client/tests/integration_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2612,15 +2612,12 @@ fn test_none_step() {
let g = traversal().with_remote(client);

//The addition of a None step however should not IO a vertex back
let mut iter = g
.add_v("test_none_step")
g.add_v("test_none_step")
.none()
.iter()
.expect("Should get a iter back");
assert!(
iter.next().is_none(),
"But the iter should have no elements because of the None step"
);
.expect("Should get a iter back")
.iterate()
.expect("Shouldn't error consuming iterator");

//Make sure the vertex is present in the graph
let vertex_count = g
Expand Down

0 comments on commit bce3737

Please sign in to comment.