Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DependsOnAsync, AddTasksAsync and DoAsync naming #305

Open
mzorec opened this issue Apr 16, 2020 · 4 comments
Open

DependsOnAsync, AddTasksAsync and DoAsync naming #305

mzorec opened this issue Apr 16, 2020 · 4 comments

Comments

@mzorec
Copy link
Collaborator

mzorec commented Apr 16, 2020

Suggestion from @huanlin :

While fixing this bug, one idea popped up:

The tasks configured with DependsOnAsync method are actually executed with Task.Run, which is arguably not asynchronous calls. I mean the following code in TaskBase.cs:

protected virtual async Task<TResult> DoExecuteAsync(ITaskContextInternal context)
{
    return await Task.Run(() => DoExecute(context));
}

Having said that, I don't have better ideas to run those "Async" tasks simply because we don't know what those user-defined tasks really do (could be CPU-bound or I/O bound).

I'm just feel that DependsOnAsync might mislead people, make them think that those tasks are executed with C# asynchronous calls.

So one possible change is to rename DependsOnAsync to something else, maybe DependsOnParallel or DependsOnConcurrently ?

I may be wrong or missed something though. So this is just a note. No further action requested. (discussions are welcomed)

@mzorec
Copy link
Collaborator Author

mzorec commented Apr 16, 2020

I'm just feel that DependsOnAsync might mislead people, make them think that those tasks are executed with C# asynchronous calls.

We actually had this discussion before with my brother. The problem is that it might be parallel or it might be async. You are looking at the implementation in the TaskBase which is misleading because it's a base class and DoExecuteAsync can be overriden..

For example take implementation of this simple task:

        protected override async Task<int> DoExecuteAsync(ITaskContextInternal context)
        {
            await Task.Delay(_delay);

            return 0;
        }

This task is executed with C# asynchronus call.

So DependsOnAsync naming is so so. Probably better name would be as you suggested because currently more tasks are really not made with asynchronus calls but in some scenarios it might also be misleading. But there is another problem with DoAsync everything with it will almost surely gona be made with asynchronus calls.

    protected override void ConfigureTargets(ITaskContext context)
        {
            context.CreateTarget("Sample").DoAsync(Sample);
        }

        private async Task Sample(ITaskContext context)
        {
            var httpClient = new HttpClient();

           await httpClient.GetAsync("");
        } 

So we should change DependsOnAsync to DependsOnConcurrent but leave DoAsync? This might also be confusing.

I am affraid that here we will not find the "100% right" solution but we can definetly change if there are some really good arguments why should we change or If more people votes for any of the proposed solutions

Edit: Oh yea and if we take this scenario:

  context.CreateTarget("Rebuild")
            .SetAsDefault()
            .AddTask(x => x.Do(t => { Console.WriteLine("running Rebuild."); }))
            .DependsOnAsync(doExample, doExample2)
            .DependsOn(test); 

This is not parallel anymore :)

@mzorec mzorec changed the title DependsOnAsync, AddTasksAsync naming DependsOnAsync, AddTasksAsync and DoAsync naming Apr 16, 2020
@huanlin
Copy link
Collaborator

huanlin commented Apr 16, 2020

With your examples, now I understand more about it, and I don't have better ideas for now.
Maybe just put some words in documents to avoid misunderstanding.... wait, I do see "parallel" mentioned in the document: Asynchronus or parallel execution of tasks, customCode and dependencies.

So yeah, maybe we do nothing for now, wait and see if there are more ideas coming up later.

@mzorec
Copy link
Collaborator Author

mzorec commented Apr 16, 2020

Maybe also some better explanation on the method documentation (summary).

@mzorec
Copy link
Collaborator Author

mzorec commented Apr 16, 2020

If you think or anyone else how could this be explained better in the documentation Asynchronus or parallel execution of tasks, customCode and dependencies or you fell some parts are missing. PR would be more than welcome. Also if anyone have an idea how could we explain this briefly in method documentation please provide a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants