automatic function concurrent with closing