
Untitled
By: a guest on
Jun 10th, 2012 | syntax:
None | size: 5.79 KB | hits: 24 | expires: Never
// JS
window.queue.dequeue(function(payload) {
alert('Anonymous Function:' + payload);
});
// CPP
NS_IMETHODIMP Queue::Dequeue(IQueueCallback *callback)
{
fprintf(stderr,"Calling Dequeue Starting New Thread\n");
callback_ = callback;
NS_IF_ADDREF(callback_);
pthread_t dequeue_thread;
int rc = pthread_create(&dequeue_thread, NULL, run_dequeue, this);
if (rc) {
fprintf(stderr, "Error from pthread_create\n");
exit(-1);
}
return NS_OK;
//return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/*
* This will call the callback set by the Dequeue method above
*/
void
Queue::dequeue_helper()
{
fprintf(stderr,"Start Sleeping 1\n");
usleep(10000000);
fprintf(stderr,"Done Sleeping 2\n");
if (callback_) {
fprintf(stderr,"Calling Callback\n");
callback_->Call("Hello World\n");
}
}
/*
* Run the Dequeuing Thread
*/
static void* run_dequeue(void* interface)
{
fprintf(stderr,"Calling run_dequeue\n");
Queue* queue = (Queue*) interface;
queue->dequeue_helper();
return NULL;
}