Flexible Thread / Asynchronous Behavior

Is Flex either single-threaded or asynchronous? If so, how can a programming model behave differently? Please explain the copy to me, and I cornered it.

+4
source share
5 answers

It is more correct to say Flash instead of Flex. Flex is just a framework, and such fundamental concepts as threads and asynchrony are related to technology, that is, to Flash.
Yes, Flash is single-threaded: you cannot create threads yourself. But there are times when flash provides you with asynchrony. For example HttpService , WebService , URLLoader classes

What does it mean? This means that from the moment you send your request at the moment, when you receive a response, you can continue to run another code and update the display list. And when you get a response, events are dispatched (or when the request fails).

Also in AIR, some file operations can be processed asynchronously ( copyToAsync , deleteFileAsync , getDirectoryListingAsync , ...). The same thing here: during copying a file, for example, you get a progress event, and you can update the views (for example, progress bar).

+3
source

Please note that you can use multithreading with Flash using the external module Alchemy (program C) or PixelBender (image processing). By the way, Adobe is currently working on the possibility of running multiple SWF files in different streams.

And given the difference between multi-threaded and asynchronous behavior, just remember that Flash is "frame-based." Each code you write, even when listening to an asynchronous event, will be executed in a specific and linear thread in each frame cycle.

+1
source

Flex / ActionScript single-threaded Flash is not. Some operations, such as URLLoader, create another thread that you cannot control. Once it completes, you will receive the event from the URLLoader object.

0
source

The short answer is, the code interpreted by Flash Player is single-threaded, but Flash Player itself is multi-threaded, so you can have asynchronous events / functions.

0
source

As mentioned earlier, the actual threading of a process is handled at the player level, which currently does not support true multithreading.

However, this does not mean that you cannot have a programming model that behaves asynchronously. It is safe to say that the goal of any flash application is to control the display anyway, so any processing strategy is really driven by a display list.

If we talk about the asynchronous programming model in Flex, they most likely refer to the invalidation / update process that takes place in the life cycle of Flex components . This creates a way to start costly processes in the next update of the display list, creating a semi-asynchronous programming model.

This type of multi-threaded multithreading is also important for applications that require many iterations over large data sets, such a complex data visualization. A large algorithm can be defined as a series of small pieces, each of which is processed when the display list is updated (frame change). This allows the rest of the application to handle events and make any display updates before processing the next fragment.

0
source

Source: https://habr.com/ru/post/1347865/


All Articles