-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Subscriptions support #846
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
18826e1
Rough take on subscriptions
leebyron b8a3c74
Minor refactoring of execute.js to make it more clear that most of su…
leebyron 74a7dc6
feat(subscriptions): expose `subscribe` in the bundle
Urigo 1242665
feat(subscriptions): added unit tests
Urigo 0dd3ce3
feat(subscriptions): added error handling and fixed tests
Urigo ba0f60e
feat(subscriptions): added test cases for querying multiple subscript…
Urigo e989ae5
feat(subscriptions): split subscribe function
Urigo 0d8380f
feat(subscriptions): export getSubscriptionEventSource
Urigo e3f695c
feat(subscriptions): added `subscribe` to field flow type
Urigo a76e7a3
Merge branch 'master' into subscriptions
Urigo 54ca988
feat(subscriptions): minor fixes
Urigo 5f25f53
feat(subscriptions): added test for multiple subscribers for the same…
Urigo 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 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 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 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 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 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 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 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
64 changes: 64 additions & 0 deletions
64
src/subscription/__tests__/eventEmitterAsyncIterator-test.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) 2017, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import EventEmitter from 'events'; | ||
import eventEmitterAsyncIterator from './eventEmitterAsyncIterator'; | ||
|
||
describe('eventEmitterAsyncIterator', () => { | ||
|
||
it('subscribe async-iterator mock', async () => { | ||
// Create an AsyncIterator from an EventEmitter | ||
const emitter = new EventEmitter(); | ||
const iterator = eventEmitterAsyncIterator(emitter, 'publish'); | ||
|
||
// Queue up publishes | ||
expect(emitter.emit('publish', 'Apple')).to.equal(true); | ||
expect(emitter.emit('publish', 'Banana')).to.equal(true); | ||
|
||
// Read payloads | ||
expect(await iterator.next()).to.deep.equal( | ||
{ done: false, value: 'Apple' } | ||
); | ||
expect(await iterator.next()).to.deep.equal( | ||
{ done: false, value: 'Banana' } | ||
); | ||
|
||
// Read ahead | ||
const i3 = iterator.next().then(x => x); | ||
const i4 = iterator.next().then(x => x); | ||
|
||
// Publish | ||
expect(emitter.emit('publish', 'Coconut')).to.equal(true); | ||
expect(emitter.emit('publish', 'Durian')).to.equal(true); | ||
|
||
// Await out of order to get correct results | ||
expect(await i4).to.deep.equal({ done: false, value: 'Durian'}); | ||
expect(await i3).to.deep.equal({ done: false, value: 'Coconut'}); | ||
|
||
// Read ahead | ||
const i5 = iterator.next().then(x => x); | ||
|
||
// Terminate emitter | ||
await iterator.return(); | ||
|
||
// Publish is not caught after terminate | ||
expect(emitter.emit('publish', 'Fig')).to.equal(false); | ||
|
||
// Find that cancelled read-ahead got a "done" result | ||
expect(await i5).to.deep.equal({ done: true, value: undefined }); | ||
|
||
// And next returns empty completion value | ||
expect(await iterator.next()).to.deep.equal( | ||
{ done: true, value: undefined } | ||
); | ||
}); | ||
}); |
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.
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.
Could you remove this line and rebase this PR from master branch again?
Some of the less-related parts of this PR have been already merged into master
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.
Done!