@@ -607,7 +607,6 @@ void Statement::EIO_Each(eio_req *req) {
607607 STATEMENT_INIT (EachBaton);
608608
609609 Async* async = baton->async ;
610- fprintf (stderr, " async:%p\n " , async);
611610
612611 sqlite3_mutex* mtx = sqlite3_db_mutex (stmt->db ->handle );
613612
@@ -620,41 +619,39 @@ void Statement::EIO_Each(eio_req *req) {
620619
621620 if (stmt->Bind (baton->parameters )) {
622621 while (true ) {
623- fprintf (stderr, " before mutex\n " );
624622 sqlite3_mutex_enter (mtx);
625623 stmt->status = sqlite3_step (stmt->handle );
626624 if (stmt->status == SQLITE_ROW ) {
627625 sqlite3_mutex_leave (mtx);
628626 Row* row = new Row ();
629627 GetRow (row, stmt->handle );
630628
631- // pthread_mutex_lock(&async->mutex);
629+ pthread_mutex_lock (&async->mutex );
632630 async->data .push_back (row);
633631 retrieved++;
634- // pthread_mutex_unlock(&async->mutex);
635-
636- fprintf (stderr, " retrieved:%d\n " , retrieved);
637- // uv_async_send(&async->watcher);
632+ pthread_mutex_unlock (&async->mutex );
633+
634+ uv_async_send (&async->watcher );
638635 }
639636 else {
640637 if (stmt->status != SQLITE_DONE ) {
641638 stmt->message = std::string (sqlite3_errmsg (stmt->db ->handle ));
642639 }
643640 sqlite3_mutex_leave (mtx);
644- fprintf (stderr, " done\n " );
645641 break ;
646642 }
647643 }
648644 }
649- fprintf (stderr, " retrieved:%d\n " , retrieved);
650645
651646 async->completed = true ;
652- // uv_async_send(&async->watcher);
647+ uv_async_send (&async->watcher );
653648}
654649
655650void Statement::CloseCallback (uv_handle_t * handle) {
656651 assert (handle != NULL );
657- fprintf (stderr, " close callback\n " );
652+ Async* async = static_cast <Async*>(handle->data );
653+ delete async;
654+ handle->data = NULL ;
658655}
659656
660657void Statement::AsyncEach (uv_async_t * handle, int status) {
@@ -680,16 +677,15 @@ void Statement::AsyncEach(uv_async_t* handle, int status) {
680677 Rows::const_iterator it = rows.begin ();
681678 Rows::const_iterator end = rows.end ();
682679 for (int i = 0 ; it < end; it++, i++) {
683- // argv[1] = RowToJS(*it);
680+ argv[1 ] = RowToJS (*it);
684681 async->retrieved ++;
685- // TRY_CATCH_CALL(async->stmt->handle_, baton->callback, 2, argv);
686- // delete *it;
682+ TRY_CATCH_CALL (async->stmt ->handle_ , baton->callback , 2 , argv);
683+ delete *it;
687684 }
688685 }
689686 }
690687
691688 if (async->completed ) {
692- fprintf (stderr, " completed\n " );
693689 if (!baton->completed .IsEmpty () &&
694690 baton->completed ->IsFunction ()) {
695691 Local<Value> argv[] = {
@@ -698,9 +694,7 @@ void Statement::AsyncEach(uv_async_t* handle, int status) {
698694 };
699695 TRY_CATCH_CALL (async->stmt ->handle_ , baton->completed , 2 , argv);
700696 }
701- // uv_close((uv_handle_t*)handle, CloseCallback);
702- delete async;
703- handle->data = NULL ;
697+ uv_close ((uv_handle_t *)handle, CloseCallback);
704698 }
705699}
706700
0 commit comments