implement a more flexable way to exit worker loop