Say, I would like to have a stream that emits a new job 1 second after the previous job is done. The job should be emitted as soon as it's created, so the subscriber can track its progress. How could this be achieved?
var currentJob = Observable.Interval(TimeSpan.FromSeconds(1))
.Select(i => new Job(i))
// .MergeWhen(job => job.IsDone)?
Edit: I understand it's easy to do this in a TPL/Rx mashup flavor; I'm mostly curious that if there is a more Rx-native approach. Based on my experience, if I can't express a logic in a Rx-native way, most of the time it's because I'm not thinking in the Rx way correctly, so insights on how to think about this kind of workflow is also welcome.
Considering you have some kind of job request stream, which produces parameters for the job:
You could build the stream of jobs with a delay between them with something like this:
where JobCompletionWait is an extension that does some kind of async spin wait for the job to complete:
To test this I launched LinqPad and wrote a dummy
Jobclass:and subscribed to the
jobTrackingStreamwith:The result was:
....
Which seems to be the expected behaviour. Maybe there is a more clean solution but this one is just something that came to my mind.
Edit: I found task-less solution, without subjects: