3 ms·
> Thanks. `await` in Perl 6 is blocking. I'm guessing Task.WaitAll maybe does (some of) what `await` does in Perl 6? Depends on what you're trying to do. `awai
by manigandham 11y ago
> Thanks. `await` in Perl 6 is blocking. I'm guessing Task.WaitAll maybe does (some of) what `await` does in Perl 6?
Depends on what you're trying to do. `await` is just a keyword that means the CPU pauses this method until the result comes back and does some other stuff meanwhile. You can omit the keyword and method completes immediately while the other stuff gets done automatically if you dont care about the result or whether it actually finished/errored/etc.
In C#, you can use Task.WaitAll() which will block the current thread until all the async tasks are finished or use Task.WhenAll() which itself is an async task that returns when all the tasks you pass in are finished (and probably the better option in actual production code).
> Are you saying ordinary synchronous C# code looks like this:
No, normal foreach is a language keyword/construct that just looks like:
foreach(var item in someListOfItems) {
DoSomething(item);
}
Parallel is a static class that implements parallel processing and is part of the TPL (Task Parallel Library) that has been available for years before even the async/await keywords were built-in. You can use them both in combination to manage async tasks and also do more explicit parallel threading yourself. It all depends on how much control you want and your objectives. I suggest looking at the link I posted to see some of the available options.
This is a good overview to the async/await in C#:
http://www.dotnetperls.com/async http://www.dotnetperls.com/async