File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,14 @@ def listen
3131					end 
3232				end 
3333
34+ 				def  each 
35+ 					return  to_enum  unless  block_given? 
36+ 					
37+ 					while  response  =  self . listen 
38+ 						yield  response 
39+ 					end 
40+ 				end 
41+ 				
3442				def  subscribe ( channels ) 
3543					@connection . write_request  [ 'SUBSCRIBE' ,  *channels ] 
3644					@connection . flush 
Original file line number Diff line number Diff line change 6868	ensure 
6969		subscription . close 
7070	end 
71+ 	
72+ 	with  "#each"  do 
73+ 		it  "should iterate over messages"  do 
74+ 			subscription  =  client . subscribe ( news_channel ) 
75+ 			
76+ 			listener  =  reactor . async  do 
77+ 				subscription . each  do  |type ,  name ,  message |
78+ 					expect ( type ) . to  be  == 'message' 
79+ 					expect ( name ) . to  be  == news_channel 
80+ 					expect ( message ) . to  be  == 'Hello' 
81+ 					
82+ 					break 
83+ 				end 
84+ 			end 
85+ 			
86+ 			client . publish ( news_channel ,  'Hello' ) 
87+ 			
88+ 			listener . wait 
89+ 		ensure 
90+ 			subscription . close 
91+ 		end 
92+ 	end 
7193end 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments