Make the synchronized callback machinery more abstract and reusable