Skip to content

Commit

Permalink
supports asynciterator
Browse files Browse the repository at this point in the history
  • Loading branch information
cdmbase committed Sep 12, 2017
1 parent f1cd86d commit 4308710
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
28 changes: 21 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-rabbitmq-subscriptions",
"version": "1.0.10",
"version": "1.1.0",
"description": "A graphql-subscriptions PubSub Engine using RabbitMQ",
"main": "dist/index.js",
"repository": {
Expand Down Expand Up @@ -30,18 +30,32 @@
"custom": "npm run compile && mocha --compilers js:babel-core/register --reporter spec --full-trace ./dist/test/custom-tests.js ",
"prepublish": "npm run integration"
},
"jest": {
"testEnvironment": "node",
"roots": [
"src"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "/__tests__/.*test*\\.(ts|tsx|js)$"
},
"dependencies": {
"@types/bunyan": "^1.8.0",
"async": "^2.5.0",
"graphql-subscriptions": "^0.4.2",
"graphql-subscriptions": "^0.4.4",
"rabbitmq-pub-sub": "^0.2.5"
},
"devDependencies": {
"@types/amqplib": "^0.5.1",
"@types/bluebird": "^3.0.37",
"@types/chai": "^3.4.34",
"@types/chai-as-promised": "0.0.29",
"@types/graphql": "^0.8.2",
"@types/mocha": "^2.2.39",
"@types/node": "7.0.5",
"@types/promises-a-plus": "^0.0.27",
Expand All @@ -56,19 +70,19 @@
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"bluebird": "^3.4.7",
"@cdm-logger/server": "^3.0.1",
"@cdm-logger/server": "^3.0.2",
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"graphql": "^0.8.0 || ^0.9.0",
"graphql": "^0.10.5",
"istanbul": "1.0.0-alpha.2",
"mocha": "^3.0.0",
"remap-istanbul": "^0.8.4",
"simple-mock": "^0.7.0",
"tslint": "^4.4.2",
"typescript": "^2.1.5"
"typescript": "^2.3.4"
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
}
}
}
14 changes: 7 additions & 7 deletions src/pubsub-async-iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ import { PubSubEngine } from 'graphql-subscriptions/dist/pubsub-engine';
*/
export class PubSubAsyncIterator<T> implements AsyncIterator<T> {

private pullQueue: Function[];
private pushQueue: any[];
private eventsArray: string[];
private allSubscribed: Promise<number[]>;
private listening: boolean;
private pubsub: PubSubEngine;

constructor(pubsub: PubSubEngine, eventNames: string | string[]) {
this.pubsub = pubsub;
this.pullQueue = [];
Expand Down Expand Up @@ -60,13 +67,6 @@ export class PubSubAsyncIterator<T> implements AsyncIterator<T> {
return this;
}

private pullQueue: Function[];
private pushQueue: any[];
private eventsArray: string[];
private allSubscribed: Promise<number[]>;
private listening: boolean;
private pubsub: PubSubEngine;

private async pushValue(event) {
await this.allSubscribed;
if (this.pullQueue.length !== 0) {
Expand Down
3 changes: 1 addition & 2 deletions src/test/integration-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ describe('SubscriptionManager', function () {
let subscriberId;
const callback = function (err, payload) {
try {
expect(payload).to.be.undefined;
expect(err.message).to.equals(
expect(payload.errors[0].message).to.equals(
'Variable "$uga" of required type "Boolean!" was not provided.',
);
setTimeout(() => done(), 2);
Expand Down

0 comments on commit 4308710

Please sign in to comment.