-
Notifications
You must be signed in to change notification settings - Fork 151
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fa929b8
Fix backpressure in the `rxSession`
bigmontz 2840237
Back-pressured stream
bigmontz df7d4bf
Fix streaming
bigmontz 084554b
Improve the flow control
bigmontz ef2c701
Fix rxjs version
bigmontz 2372018
Skip flacky test
bigmontz 62af7cd
Flacky
bigmontz 0a50745
Remove unused imports
bigmontz ef6a416
Docs and examples
bigmontz 875e712
Add unit tests part1
bigmontz ba775fe
Tests
bigmontz d922066
Add ts declarations
bigmontz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,16 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import neo4j from '../src' | ||
import neo4j, { session } from '../src' | ||
import sharedNeo4j from './internal/shared-neo4j' | ||
import { ServerVersion, VERSION_4_0_0 } from '../src/internal/server-version' | ||
import { map, materialize, toArray } from 'rxjs/operators' | ||
import { | ||
bufferCount, | ||
map, | ||
materialize, | ||
mergeMap, | ||
toArray | ||
} from 'rxjs/operators' | ||
import { Notification } from 'rxjs' | ||
|
||
/** | ||
|
@@ -1529,6 +1535,66 @@ describe('#integration examples', () => { | |
} | ||
}) | ||
}) | ||
|
||
describe('back-pressure', () => { | ||
it('should control flow by manual push records to the stream', done => { | ||
const driver = driverGlobal | ||
|
||
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) | ||
}) | ||
}) | ||
}) | ||
|
||
it('should control flow by resume and pause the stream', async () => { | ||
const driver = driverGlobal | ||
const callCostlyApi = async () => {} | ||
|
||
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() | ||
} | ||
Comment on lines
+1571
to
+1596
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Examples for pause and resume |
||
}) | ||
}) | ||
|
||
function removeLineBreaks (string) { | ||
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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