Android Question Clarification: Resumable Subs

epiCode

Active Member
Licensed User
Small clarification needed regarding Resumable Sub/Wait for Event consumption

I have a sub called TTSCompleted which is called by a lib

in main code I use the following statement
B4X:
Wait for TTSCompleted

When the event happens "Wait for" apparently resumes but the Sub TTSCompleted is not called

If I remove "wait for" then Sub is called normally.

So, my question is
1. Are events getting consumed and not pass to all listeners?
2. What can be done to have both sub and "wait for" receive the event?

Thanks!
 

Lucas Siqueira

Active Member
Licensed User
Longtime User
Small clarification needed regarding Resumable Sub/Wait for Event consumption

I have a sub called TTSCompleted which is called by a lib

in main code I use the following statement
B4X:
Wait for TTSCompleted

When the event happens "Wait for" apparently resumes but the Sub TTSCompleted is not called

If I remove "wait for" then Sub is called normally.

So, my question is
1. Are events getting consumed and not pass to all listeners?
2. What can be done to have both sub and "wait for" receive the event?

Thanks!

B4X:
Private TTS1 As TTS
TTS1.Initialize("TTS1")
TTS1.Speak("big brother",True)
Wait For TTS1_Ready(Success As Boolean)
Log(Success)
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
If you remove the Wait For, then you are calling TTSCompleted, not the library. Also, since TTSCompleted suddenly is called, that means that you actually have a sub named TTSCompleted. That's not how Wait For works.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I'm going to guess that your code is something like
B4X:
CallingSomeLibrarySub
Wait For TTSCompleted
Log("First Line After Wait For")

Public Sub TTSCompleted
 Log("I'm the sub called TTSCompleted")
End Sub
Where CallingSomeLibrarySub calls TTSCompleted and therefore you are expecting
I'm the sub called TTSCompleted
First Line After Wait For
But you're getting
First Line After Wait For
And that is because that is how Wait For works. The code flow with Wait For is:
B4X:
CallingSomeLibrarySub
Wait For TTSCompleted
Log("Processing TTSCompleted")
 
Upvote 0

epiCode

Active Member
Licensed User
B4X:
Private TTS1 As TTS
TTS1.Initialize("TTS1")
TTS1.Speak("big brother",True)
Wait For TTS1_Ready(Success As Boolean)
Log(Success)
hi @Lucas Siqueira ,
Isn't TTS1_Ready an event which is triggered after successful initialization of TTS ?


And that is because that is how Wait For works. The code flow with Wait For is:
B4X:
CallingSomeLibrarySub
Wait For TTSCompleted
Log("Processing TTSCompleted")
this is what I tried and it works fine now. Thanks for your help @OliverA .
B4X:
....some sub
wait for Complete
....

TTS1_ttsFinished
some handling code
callsub(Me,"Complete")
End Sub

[
 
Upvote 0

epiCode

Active Member
Licensed User
This is the wrong way to wait for a sub to complete.

The correct way is: [B4X] Resumable subs that return values (ResumableSub)


B4X:
 Wait for (TTS1_ttsFinished) Complete
Tried this and also removed "callsub(me, "Complete")
it causes tts1_ttsFinished to be called after "wait for" line

However my expectation is:

"Wait for" to wait until the lib triggers TTS1_ttsFinished and resumed when TTS1_ttsFinished is completed.
Is that possible without using the incorrect method I shared earlier?
Thanks!!
 
Upvote 0

epiCode

Active Member
Licensed User
It should be: Wait For TTS1_ttsFinished

The Wait For (Sender) Complete pattern is for subs that return ResumableSubs objects.
That brings me back to my first post.
I saw that ilan has shared a similar issue in the thread you suggested but unfortunately could not find if it was discussed further
 
Upvote 0

epiCode

Active Member
Licensed User
1. Yes. Wait For will "steal" the event.
2. Call the sub after Wait For.
Allow me to say @Erel that your brilliantly simple one line solutions make me say "wow" and "what was me thinking" in the same breath every time :)
 
Upvote 0
Top