Refactored invoke_when_ready callback to be its shared state