public void OnError(Exception cause) { if (cause == null) { throw new ArgumentNullException(nameof(cause)); } lock (this) { if (Volatile.Read(ref cancelled)) { return; } if (done) { return; } done = true; if (emitting) { error = cause; return; } } actual.OnError(cause); }