Question

Here is a simple question. suppose that I have a very long loop to execute, It would be nice to keep the user informed about the progressing right? I would print for example the number of loops that have been executed so far and how many are remaining. The problem that I have is those output wouldn't be visualized until the the loop is finished, and thus there will be no point for them to be displayed. I'm sure that there is some method in dart that can some sort of a handler to the browser to execute tasks and events whenever I want to and keep running the loop. I'm new to dart, I hope that someone could answer this question. Thank you.

PS: If you don't know how to, you can give me any ideas of keywords that I can use to look for this particular feature in dart documentation, it will be very helpful.

Was it helpful?

Solution 2

I think too that Isolates are the best approach but wasn't successful using them on the browser a while ago, but there was a bigger refactoring going on lately in Isolates.

Does anyone know of a current client side Isolates example? The API doc referenced by @kevmoo contains a link to an Isolates article that doesn't exist anymore (maybe must be rewritten due to the mentioned refactoring).

Another approach would be a method that returns after a chunk of work and gets recalled repeated in a loop until it returns for example true for done (false for not yet). When you call this method using scheduleMicrotask(doChunk) or new Timer(() => doChunk()) other tasks get some air (import 'dart:async';) each time before the method gets actually called.

OTHER TIPS

You can dig into Isolates, which allow background work on supported browsers.

https://api.dartlang.org/docs/channels/stable/latest/dart_isolate.html

Nothing as simple as DoEvents(), but all of the pieces are there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top