Android Question How to avoid using "Wait For"

LucaMs

Expert
Licensed User
Longtime User
I would like to avoid forcing the user of my class to use "WAIT FOR" while waiting for a class routine to finish moving a View.

Example (Duration, SomeView, ... fake stuff, only as example)
B4X:
' clsMyClass
Public Sub Move
   SomeView.SetLayoutAnimated(Duration, 100, ...)
End Sub

I wish the user-developer could write like this:
B4X:
objMyClass.Move
Log("Done") ' <--- this line executed only after Duration ms

And not like:
B4X:
Wait For (objMyClass.Move) Complete(Unused As Boolean)
Log("Done") ' <--- this line executed only after Duration ms
 

agraham

Expert
Licensed User
Longtime User
wish the user-developer could write like this:
No such thing.
For clarification, the reason it is not possible is that for Wait For to work the sub-routine call stack has to be totally unwound back to the message loop, which means that every call has to return. So your objMyClass.Move has to return or it will block and not let the message loop process the wait.
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
The resumable subs feature is a 100% B4X compiler feature.
So, Lucas can put the 'wait for' in his class itself (maybe with some parameter) and compiler will work.
No need for 'wait for' in calling program .

Regards,

Anand
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
So, Lucas can put the 'wait for' in his class itself (maybe with some parameter) and compiler will work.
No need for 'wait for' in calling program .
Nope. The developer must call the resumable sub with Wait For, otherwise the developer code will not wait for the class method to complete.

As I said, you must use Wait For if you want the execution to wait for something. There is no other (good) option.

So this means that no other language that targets Android has this feature ??
.Net - Xamarin includes a similar feature (async / await). It is not exactly the same and it doesn't work with events.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
So this means that no other language that targets Android has this feature ??
Xamarin (C#) has a similar await statement but the impementation is totally different as C# has the ability to save and resume executiom contexts whereas (as far as I know) Java doesn't.
 
Upvote 0
Top