public Task SetState(S newState) { var source = new TaskCompletionSource <object>(); updateContext.OnNextUpdate(() => { state = newState; source.TrySetResult(null); }); return(source.Task); }