-
Notifications
You must be signed in to change notification settings - Fork 149
Improve back-pressure mechanism for RxResult #882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or 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
bigmontz
commented
Feb 28, 2022
Comment on lines
+1543
to
+1563
const session = driver.rxSession() | ||
const xs = [] | ||
|
||
const result = session.run('UNWIND RANGE(0, 10) AS x RETURN x') | ||
result | ||
.records() | ||
.pipe(map(record => record.get('x').toInt())) | ||
.subscribe({ | ||
next: async x => { | ||
xs.push(x) | ||
// manual pushing reoords to the stream | ||
// it pauses the automatic pushing | ||
await result.push() | ||
}, | ||
complete: async () => { | ||
expect(xs).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | ||
await session.close().toPromise() | ||
done() | ||
}, | ||
error: done.fail.bind(done) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage for result.push api
bigmontz
commented
Feb 28, 2022
Comment on lines
+1571
to
+1596
const session = driver.rxSession() | ||
|
||
try { | ||
const result = session.run('UNWIND RANGE(0, 10) AS x RETURN x') | ||
const xs = await result | ||
.records() | ||
.pipe( | ||
map(record => record.get('x').toInt()), | ||
bufferCount(5), // buffer 5 records | ||
mergeMap(async theXs => { | ||
// pausing the records coming from the stream | ||
result.pause() | ||
// some costly operation | ||
await callCostlyApi(theXs) | ||
// resume the stream | ||
await result.resume() | ||
return theXs | ||
}), | ||
toArray() | ||
) | ||
.toPromise() | ||
|
||
expect(xs).toEqual([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10]]) | ||
} finally { | ||
await session.close().toPromise() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Examples for pause and resume
rxSession
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The lack of consumer oriented back-pressure mechanism in the RxJS apis was causing memory issues and other problems in the client code.
For solving this issue, the records observer returned by
RxResult.records()
was changed for using the async iterator as foundation. New methods for enabling the client for fine controlling the stream were added to theRxResult
api. These methods are:pause()
: Pause the record streaming. No new record will be pushed to the stream utilpush
orresume
get called.resume()
: Resumes the records streaming.push()
: Push the next record. If the stream is not paused, this method will pause it for giving the push control to the client.