added support for closing files non-blocking