File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -130,4 +130,27 @@ suite('Basic Communication', function() {
130130 } ) ;
131131
132132 } ) ;
133+
134+ test ( 'client to server: pending events support' , function ( done , server , client ) {
135+ server . evalSync ( createServerStream , 'hello' ) ;
136+
137+ server . evalSync ( function ( ) {
138+ helloStream . on ( 'evt2' , function ( d1 , d2 ) {
139+ emit ( 'evt2' , d1 , d2 ) ;
140+ } ) ;
141+ emit ( 'return' ) ;
142+ } ) ;
143+
144+ server . on ( 'evt2' , function ( d1 , d2 ) {
145+ assert . deepEqual ( d1 , { abc : 1001 } ) ;
146+ assert . equal ( d2 , 200 ) ;
147+ done ( ) ;
148+ } ) ;
149+
150+ client . evalSync ( function ( ) {
151+ var stream = new Meteor . Stream ( 'hello' ) ;
152+ stream . emit ( 'evt2' , { abc : 1001 } , 200 ) ;
153+ emit ( 'return' ) ;
154+ } ) ;
155+ } ) ;
133156} ) ;
Original file line number Diff line number Diff line change @@ -7,12 +7,20 @@ Meteor.Stream = function Stream(name, callback) {
77 var subscription ;
88 var subscriptionId ;
99
10+ var connected = false ;
11+ var pendingEvents = [ ] ;
12+
1013 self . _emit = self . emit ;
1114
1215 collection . find ( { } ) . observe ( {
1316 "added" : function ( item ) {
1417 if ( item . type == 'subscriptionId' ) {
1518 subscriptionId = item . _id ;
19+ connected = true ;
20+ pendingEvents . forEach ( function ( args ) {
21+ self . emit . apply ( self , args ) ;
22+ } ) ;
23+ pendingEvents = [ ] ;
1624 } else {
1725 var context = { } ;
1826 context . subscriptionId = item . subscriptionId ;
@@ -25,7 +33,11 @@ Meteor.Stream = function Stream(name, callback) {
2533 subscription = Meteor . subscribe ( streamName , callback ) ;
2634
2735 self . emit = function emit ( ) {
28- Meteor . call ( streamName , subscriptionId , arguments ) ;
36+ if ( true ) {
37+ Meteor . call ( streamName , subscriptionId , arguments ) ;
38+ } else {
39+ pendingEvents . push ( arguments ) ;
40+ }
2941 } ;
3042
3143 self . close = function close ( ) {
You can’t perform that action at this time.
0 commit comments