fscom.Async: Types Modinfo Source  

Asynchronus Tasks

This module contains the base types to handle asynchronous tasks. It's inspired by Java's concurrent library.

Create a task by extending TTask and override Execute. Submit the task to an executor. The executor will decide when there is a good time to do the task. The returned future can be used to keep track of the task.

Use fscom.AsyncEx to use some example implementations.

Types Summary

TExecutor An executor that will execute tasks.
TFuture A Future is an result of an asynchronus task.
TTask This represents a task.

Types

Type TExecutor
DescriptionAn executor that will execute tasks.
InformationExecutors will execute taska that are submitted. The tasks may be executed in different threads or in the thread Submit or any other method was called.
Methods Summary
ExecuteAll Executes all Tasks and waits for all of them to be done.
ExecuteAny Executes some Tasks and waits for one to be done and returns its result.
Shutdown Makes the executor refuse to take any more tasks.
ShutdownNow Cancels all submitted tasks and makes the executor refuse to take new tasks.
Submit Submit a task for the executor to execute.
SubmitAll Submit many tasks for the executor to execute.
WaitShutdown Waits for shutdown of this executor to be completed.
Method ExecuteAll:TFuture[](tasks:TTask[] , timeout:Int = TIMEOUT_FOREVER) Abstract
DescriptionExecutes all Tasks and waits for all of them to be done.
Method ExecuteAny:Object(tasks:TTask[] , timeout:Int = TIMEOUT_FOREVER) Abstract
DescriptionExecutes some Tasks and waits for one to be done and returns its result.
Method Shutdown() Abstract
DescriptionMakes the executor refuse to take any more tasks.
Method ShutdownNow() Abstract
DescriptionCancels all submitted tasks and makes the executor refuse to take new tasks.
Method Submit:TFuture(task:TTask) Abstract
DescriptionSubmit a task for the executor to execute.
Method SubmitAll:TFuture[](tasks:TTask[])
DescriptionSubmit many tasks for the executor to execute.
Method WaitShutdown(timeout:Int = TIMEOUT_FOREVER) Abstract
DescriptionWaits for shutdown of this executor to be completed.

Type TFuture
DescriptionA Future is an result of an asynchronus task.
InformationFutures can be obtained upon submitting a task. They can be used to synchronize threads and keep track of the started tasks.
Methods Summary
Cancel Attempt do cancel a task before it was executed.
GetTask Returns the task this future was created for.
IsCanceled Returns true if the task was cancelled and didn't run.
IsDone Returns true if the task returned a value, threw an exception or was canceled.
Wait Wait for the task to finish and return the result.
Method Cancel:Byte() Abstract
ReturnsTrue if it was successful.
DescriptionAttempt do cancel a task before it was executed.
Method GetTask:TTask() Abstract
DescriptionReturns the task this future was created for.
Method IsCanceled:Byte() Abstract
DescriptionReturns true if the task was cancelled and didn't run.
Method IsDone:Byte() Abstract
DescriptionReturns true if the task returned a value, threw an exception or was canceled.
Method Wait:Object(timeout:Int = TIMEOUT_FOREVER) Abstract
DescriptionWait for the task to finish and return the result.
InformationThis method will block and wait for the task to finish. It will throw any exception thrown by the task. It will throw a timeout exception if timeout was reached before the task returned. If the task was finished before this method is called, it will imediately return/throw the result.

Type TTask
DescriptionThis represents a task.
InformationTasks can be executed and will return a result or throw an exception.
Methods Summary
Execute Execute the task.
Method Execute:Object() Abstract
DescriptionExecute the task.
InformationThis Method MUST NOT interfere with the TTask-Object. So it is safe to call Execute in multiple Threads at once.

Module Information

Version1.0
AuthorFrancesco Silvani
Licensezlib/libpng