# nopoll_loop_wait

Definition: | include nopoll.e integer res = nopoll_loop_wait(atom ctx, integer timeout)
Description: | Implement a wait over all connections registered under the provided context during the provided timeout until something is detected meaningful to the user, calling to the action handler defined, optionally receving the user data pointer. ctx: The context object where the wait will be implemented. timeout: The timeout to wait for changes. If no changes happens, the function returns. The function will block the caller until a call to nopoll_loop_stop() is done in the case timeout passed is 0. Returns: The function returns 0 when finished without error or -2 in the case ctx is NULL or timeout is negative. Function returns -3 if timeout was reached. Function returns -4 in the case ctx->io_engine->wait failed to implement wait or it reported error. PL: note returns of -3 and -4 may not occur in older versions of the dll. Recovering from IO Wait failure (return code -4): In the case I/O wait mechanism fails, this function will return -4. In can catch that error code and recover (keep on waiting), log the error or implement some other policy.
Example: | Copy
    while true do
        -- wait for ever
        integer error_code = nopoll_loop_wait(ctx, 0)

        if error_code==-4 then
            printf(1,"Log here you had an error cause by the io waiting mechanism, errno=%d\n", errno)
            -- recover by just calling io wait engine
            -- try to limit recoveries to avoid infinite loop
        else
    ...
PL: note that errno is defined (in C) as WSAGetLastError(), not (yet) available via nopoll.e