Executing Tasks from C#

Faced with a problem that I can’t execute Task immediately after caching. Not sure if I’m doing something wrong or if it’s a problem with the chosen solution.

In short, what’s going on here. There is S3 compliant storage that I want to work with and I have chosen AWSSDK.S3 nuget for this. It uses asynchronous calls. But the thing is, you have to cache these calls each time before sending them. And it turns out that I can’t call the function I need with a button - I have to cache it first, then call the execution of the task.

Am I doing something wrong? Maybe I’m missing something?

I’ve tried pure code, now I’ve written a helper. But neither of them works as expected.

Example patch or repository would be good…

put the toobservable in the cache region.
or use a managetask region, which does the same internally

@sebl thank you very much!
This is exactly how it should be done!

I completely forgot about ManageTask, great tool if you use Tasks.

@antokhio NuGet Gallery | AWSSDK.S3 3.7.414.1

@sebl Might you have some thoughts on how to develop the following idea: creating a chain of calls? When I use ManageTask I get an Observable and can use ForEach for example. But if I use ManageTask inside ForEach (Observable), I get Observable<Observable>. What is the best way to preserve the Async structure and still easily create call chains?

Please have a look at the HowTo Chain Tasks from the Helpbrowser in the previews. The patch shows Then, Then (Value) and ThenDo regions for chaining tasks.

Best,
Anton

@robotanton Thank you so much! Very valuable insight!
I’ve already wrapped everything in ManageTask
Is there something similar for Observable? Although perhaps a scheme with channels would be even more convenient!

Wow, yep, very valuable indeed. Thanks for this one!

@robotanton

I have a small question and concern. I am currently using TelegramBot (22.7) and want to use the DownloadFile method.

The method is parsed in such a way that it gives Task (NonGeneric) output from the node. But in a pipeline consisting of Then and ThenDo, there is no place for such functions. Yes, the function is executed (I use it in the ThenDo operation), but I have a question: is this equivalent to await? Or in this case, we cannot track whether this function has been executed or not? It seems that the function is launched, but it is impossible to wait for its execution, the execution rushes on as if I did not manage to do anything.

Where the function has a result, chaining works smoothly and beautifully. But where the function has no result, a problem arises.

I made a simple illustration, but I think it may not be very clear. If it’s difficult to understand what I mean, I can try to explain it better.

TaskChainingIssue.vl (19.3 KB)

TaskChainingIssue2.vl (38.0 KB)

Important notice: I am aware of ThreadSleep, and in this specific situation, I used the Delay node as the source of the ‘non-generic task’.

TaskChainingIssue_GenericTask_Then.vl (26.7 KB)

It seems to me it is a bit tricky to work with the non-generic task returned by Delay.

Not sure if there are better solutions, but this works:

  • turned the non-generic tasks into a generic one.
  • used Then which allows to chain more task.

@gregsn Thank you very much! That’s a very good solution; I was probably close to something like that in all my experiments. I feel like it’s worth adding to the main API, although I’m not sure if the names are appropriate.

I would, of course, be happy if others joined the discussion.