Skip to content

Commit

Permalink
Finished Live Query with Observable
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Feb 14, 2017
1 parent ab98e52 commit ef16257
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
####3.0.0

### New Feature

* Live Query With Observable [#236](https://github.com/orientechnologies/orientjs/issues/236)

####2.2.4

###Bug Fixes
Expand Down
8 changes: 5 additions & 3 deletions lib/session/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ class OSession extends DB {
var iToken = response[0].token;
var wrapperCallback = function (currentToken, operation, result) {
if (currentToken == iToken) {
subscriber.next({token : currentToken , operation : operation , data : result});
subscriber.next({token: currentToken, operation: operation, data: result});
}
};

var unsubscribeCallbak = function(currentToken){
var unsubscribeCallbak = function (currentToken) {
if (currentToken == iToken) {
subscriber.complete();
}
Expand All @@ -150,7 +150,9 @@ class OSession extends DB {
this.srv.on("live-query-end", unsubscribeCallbak);

}
});
}).catch((error) => {
subscriber.error(error);
});
});

return result;
Expand Down
32 changes: 23 additions & 9 deletions test/session/session-live-query-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Promise = require('bluebird');
var Errors = require('../../lib/errors');
describe("Session API - Live Query ", function () {

this.timeout(20000);
Expand Down Expand Up @@ -63,18 +64,18 @@ describe("Session API - Live Query ", function () {
var session = this.session;
this.session.liveQuery("LIVE SELECT FROM Test")
.subscribe(function (live) {
count++;
live.data.content.name.should.eql('a');
if (count === TOTAL) {
session.query("live unsubscribe " + live.token).then(function (res) {
count++;
live.data.content.name.should.eql('a');
if (count === TOTAL) {
session.query("live unsubscribe " + live.token).then(function (res) {

});
}
}, function (err) {
});
}
}, function (err) {

}, function () {
}, function () {
done();
});
});
var self = this;
setTimeout(function () {
var promises = [];
Expand All @@ -93,4 +94,17 @@ describe("Session API - Live Query ", function () {

});

it('should trigger live query error', function (done) {

this.session.liveQuery("LIVE SELECT FROM Test2")
.subscribe(function (live) {
throw new Error('Should never happen!');
}, function (err) {
err.should.be.an.instanceOf(Errors.RequestError);
done();
}, function () {
throw new Error('Should never happen!');
});
});

});

2 comments on commit ef16257

@saeedtabrizi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maggiolo00 WOW , It's cool .
Let me sync the Typescript definition file to the new changes in orientjs before release the next version please .

@wolf4ood
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saeedtabrizi

sure, you have time. Those changes target orientjs 3.0 that will be released with OrientDB 3.0
I'm waiting for the M1 to be released and the new streaming/transaction protocol to be stable in order to implement it on OrientJS

Please sign in to comment.