danieldg / ordered-stream

Apache License 2.0
11 stars 2 forks source link

Guidance on how to create an ordered stream of results? #15

Closed jackgerrits closed 1 year ago

jackgerrits commented 1 year ago

For my use case I have several streams of results that need to be combined, if an error is hit it seems reasonable for the overall stream to return the error and stop processing. The items within the result are ordered.

I was wondering if there is any guidance or examples of using results within. I see two possible ways to go about this:

Thanks in advance.

danieldg commented 1 year ago

If errors always cause the end of the stream, then the best way to order them is to sort them "after" all other possible elements - either by using !0u64 as an ID, or as if the ordering was #[derive(PartialOrd)] enum Order { Value(...), Error } - this is how zbus works. Otherwise, you would need to include some kind of "current location" marker for transient errors.

Basically the stream needs to return something like "1, 2, 2, 3, 5, 1001, 1001, 2000"