# mco_async_event_wait
RT

> Wait on a specified asynchronous event.

### Prototype

        MCO_RET	mco_async_event_wait(	/*IN*/ mco_db_h db, /*IN*/ in event_id);

### Arguments

db | The database handle that was established by `mco_db_connect()`
event_id | The identifier assigned to the event in the generated interface header file `dbname.h`

### Description

> This function blocks the thread until the event referenced by `event_id` occurs or the application explicitly releases the event handler.

### Return Codes

MCO_S_OK | The event occurred
MCO_E_INVALID_HANDLE | The database handle is invalid
MCO_S_EVENT_RELEASED | The event was released by the application

### Example

        Application snippet:

        const char * dbname = "SimpleDb";

        MCO_RET Event_NewHndlr( sample_task_t * descriptor )
        {
            int count = 0;

            /* use the connection created by sample_start_connected_task() */
            mco_db_h db = descriptor->db_connection;
            while ( MCO_S_OK == mco_async_event_wait(db, MCO_EVENT_newEvent) )
            {
                printf("\tNewEventHandler call %d\n", count);
                count++;
            }
            printf("\tExiting NewEventHandler. Number of calls : %d\n", count);
        }

        int main(int argc, char* argv[])
        {
            mco_db_h db;
            MCO_RET rc;
            mco_device_t       dev;
            mco_db_params_t    db_params;
            mco_trans_h t;

            ...
            rc = mco_db_open_dev( dbname, simple_get_dictionary(), &dev, 1, &db_params );
            if ( MCO_S_OK != rc )
            {
                rc = mco_db_connect(  dbname, &db );
                ...
                _beginthread( Event_NewHndlr, 0, (void*)db );
                Sleep(100);
                ...
                }
            }
            ...
        }

### Files

Header file:
mco.h
Source file:
mcoevasy.c
Library:
libmcolib.a