Fix race condition when setting callbacks

Prevents a race condition that may occur if the future returns
while a callback is being set.