Giter VIP home page Giter VIP logo

Comments (3)

sebthom avatar sebthom commented on May 27, 2024

HTLM and Flash targets are single threaded. So your loop

		do {
			trace(done.toString());
		} while (!result.isComplete());

blocks any potential async execution.

Depending on the target platform a different Executor implementation is selected:

public static function create(maxConcurrent:Int = 1, autostart = true):Executor {
#if threads
if (Threads.isSupported)
return new ThreadPoolExecutor(maxConcurrent, autostart);
#end
return new TimerExecutor(autostart);
}

For HTML/Flash it is the TimerExecutor which uses haxe.Timer to schedule async execution of code. As long as you have actively running any code the execution of any scheduled async tasks is prevented.

To get true parallelism on the web one would need to use webworkers, however this has other consequences as they cannot access shared state but run in isolated processes.

from haxe-concurrent.

FlashBacks1998 avatar FlashBacks1998 commented on May 27, 2024

Out of curiosity, how can i wait or tell if all of the submissions in the TimerExecutor or ThreadPoolExecutor is completed? How would i fix the do while loop to not block any async execution?

from haxe-concurrent.

sebthom avatar sebthom commented on May 27, 2024

You need to get all your code after executor.submit(...) out of the event loop to allow the browser/flash to do event processing.
This means you need to work with callbacks. Something like:

  trace("waiting...");
  var resultFuture = executor.submit(task);
  result.onCompletion(result => {
    // your code...
  });

For HTML or Flash using the Executor will not improve performance as still only a single thread (the event loop) running on a single core is used. This is a target specific limitation. To do parallelism in Browser/HTML you could play around with webworkers but as I said this does not work with shared states and involves serialization/message passing.

from haxe-concurrent.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.