public async Task InvalidateAsync(bool force = false) { var oldJob = _loadTreeJob; var newJob = new LoadTreeJob(Tree, ct => LoadTree(force, ct)); if (oldJob != null) { oldJob.Cancel(); } Interlocked.CompareExchange(ref _loadTreeJob, newJob, oldJob); if (await newJob.WaitForLoad()) { Changed?.Invoke(this, EventArgs.Empty); } }
public async Task InvalidateAsync(bool force = false) { var oldJob = _loadTreeJob; var newJob = new LoadTreeJob(Tree, oldJob?.LoadDateTime, ct => LoadTree(force, ct)); // If we have a job pending, cancel it but wait for it to finish // so we don't accidentally trigger an abuse detection because of // too many pending async calls against the GitHub API. if (oldJob != null) { oldJob.Cancel(); try { await oldJob.WaitForLoad(); } catch { // Ignore } } Interlocked.CompareExchange(ref _loadTreeJob, newJob, oldJob); try { if (await newJob.WaitForLoad()) { Changed?.Invoke(this, EventArgs.Empty); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); } }