Add duration parameter to DataStream run method #493
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added a duration parameter to the
DataStream.run()
method, allowing users to input atimedelta
object to specify how long theDataStream
should run for.To implement this I've created a separate method called
_run
which takes thetimedelta
object and converts it into seconds. An aynscio task is then created usingasyncio.create_task(self._run_forever())
and then this task is waited for usingasyncio.wait()
. The asyncio wait function has a timeout parameter in seconds which in this case is used to cancel the running of_run_forever
when the duration is exceeded.I've also added a unit test with a number of durations to test this feature.