Android Question dynamically adding a class instance, executing a method without blocking other active instances?

Darsiar

Member
How to run the Eval method in each instance of a class from the list, in such a way that each instance works without blocking the others - as if in a different thread, or as a coroutine?
1) There is a calculator class (Script interpreter-compiler)
B4X:

' classTask --> Class Script Evaluator'

Sub Process_Globals

Public Taskname as string

Public TaskStatus as int

End Sub

Public Sub Initializi(script as string)

'....

End Sub


'begin evaluate

Public Sub Eval()

'....

End Sub



' Get my mail

Public Sub GetMail(mail as object)

'.....

End Sub



2) There is a list of active tasks in the Map form:
B4X:

Sub Process_Globals

private ActiveTask as map ' task list

End Sub



Sub Service_Create

ActiveTask.Initialze



End Sub

' Add and Run

Public AddNewActiveTask(task as classTask)

ActiveTask.Add(task.Name, task)

'Parallel RUN ---> ActiveTask.Get(name).Eval.

'???????

End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

The answer is: it depends.
Many libraries do many things in the background / asynchronously. In such cases you can use resumable subs which are similar to coroutines.

There is a calculator class (Script interpreter-compiler)
B4A performance in release mode is excellent. Implement it as simple as possible and unless you are doing something very special, it will be very fast and will not block anything.
 
Upvote 0

Darsiar

Member
need to do something like that?
But it's not clear how to tell BASIC that the method Eval does not block other instances of the class?

The fact is that from the description it follows that this will work for methods that are sleeping or waiting for something.

In our case, each Eval is fully active in calculating the script.
How to divide this activity betw?

B4X:
Sub Process_Globals
    Dim activeTask as map
   
End Sub

public Sub AddParallenTask(script As String, name as string)  
    dim newTask as taskClass
    newTask.Initialize(script,name)
   
    activeTask.Put(name, newTask)
   
    wait for newTask.eval  <-------- Eval method
    if ... then
      activeTask.Remove(name)
    end if
   
End Sub
 
Upvote 0
Top