Skip to content

Segmentedtree UpdateTrees() vs UpdateTreesInBackground() #705

@swharden

Description

@swharden

Hi @StendProg, in #692 @jl0pd commented about this method:

public async Task SetSourceAsync(T[] data)
{
if (data == null)
throw new Exception("Data cannot be null");
sourceArray = data;
await Task.Run(() => UpdateTreesInBackground());
}

@jl0pd said we are not awaiting real operation, but only the creation of a task. By doing this users may begin to work data which is not yet updated properly. This solution was offered:

public async Task SetSourceAsync(T[] data)
{
    sourceArray = data ?? throw new ArgumentNullException("Data cannot be null");
    await Task.Run(() => UpdateTrees());
}

This makes sense to me, as UpdateTreesInBackground() is just Task.Run(() => { UpdateTrees(); }), but before making this change I wanted to double check and make sure it looks good to you too. @StendProg, what do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions