Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 10th, 2012  |  syntax: None  |  size: 5.79 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // JS                                                                                                                  
  2. window.queue.dequeue(function(payload) {                                                                              
  3.   alert('Anonymous Function:' + payload);                                                                              
  4. });                                                                                                                    
  5.                                                                                                                        
  6.                                                                                                                        
  7. // CPP                                                                                                                
  8. NS_IMETHODIMP Queue::Dequeue(IQueueCallback *callback)                                                                
  9. {                                                                                                                      
  10.   fprintf(stderr,"Calling Dequeue Starting New Thread\n");                                                            
  11.   callback_ = callback;                                                                                                
  12.   NS_IF_ADDREF(callback_);                                                                                            
  13.                                                                                                                        
  14.   pthread_t dequeue_thread;                                                                                            
  15.   int rc = pthread_create(&dequeue_thread, NULL, run_dequeue, this);                                                  
  16.   if (rc) {                                                                                                            
  17.     fprintf(stderr, "Error from pthread_create\n");                                                                    
  18.     exit(-1);                                                                                                          
  19.   }                                                                                                                    
  20.                                                                                                                        
  21.   return NS_OK;                                                                                                        
  22.   //return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;                                                                  
  23. }                                                                                                                      
  24.                                                                                                                        
  25. /*                                                                                                                    
  26.  * This will call the callback set by the Dequeue method above                                                        
  27.  */                                                                                                                    
  28. void                                                                                                                  
  29. Queue::dequeue_helper()                                                                                                
  30. {                                                                                                                      
  31.   fprintf(stderr,"Start Sleeping 1\n");                                                                                
  32.   usleep(10000000);                                                                                                    
  33.   fprintf(stderr,"Done Sleeping 2\n");                                                                                
  34.                                                                                                                        
  35.   if (callback_) {                                                                                                    
  36.     fprintf(stderr,"Calling Callback\n");                                                                              
  37.     callback_->Call("Hello World\n");                                                                                  
  38.   }                                                                                                                    
  39. }                                                                                                                      
  40.                                                                                                                        
  41. /*                                                                                                                    
  42.  * Run the Dequeuing Thread                                                                                            
  43.  */                                                                                                                    
  44. static void* run_dequeue(void* interface)                                                                              
  45. {                                                                                                                      
  46.   fprintf(stderr,"Calling run_dequeue\n");                                                                            
  47.   Queue* queue = (Queue*) interface;                                                                                  
  48.   queue->dequeue_helper();                                                                                            
  49.   return NULL;                                                                                                        
  50. }