Implemented non-blocking wait function