I have a problem that is probably of my own design, I just dont know how to fix it.
Hope you can give me some pointers.
I have a big Sub in my program. To make it smaller I have taken parts out, but a "wait for" is giving me problems.
B4X:
Sub BIGSUB
...Lots of code...
Mail(some variable, email, etc)
..More code...
Mail(some variable, email, etc)
..even more code...
Mail(some variable, email, etc)
End Sub
Sub MAIL(Variable,variable,variable)
...some code that sets up a mail using smtp...
Wait For SMTP_MessageSent(Success As Boolean)
End sub
My problem is that not all mail is sendt. I guess its because the MAIL-sub isnt finnished before it gets called again)
Is there any way to fix this, other than duplicate the MAIL-code three times in the main BIG sub?
Because you have taken the 'Wait For' out of Big Sub, you have to put one there for each call to Mail (which has to be a resumable sub).
B4X:
Sub BIGSUB
...Lots of code...
Wait For (Mail(some variable, email, etc)) Complete (Success As Boolean)
..More code...
Wait For (Mail(some variable, email, etc)) Complete (Success As Boolean)
..even more code...
Wait For (Mail(some variable, email, etc)) Complete (Success As Boolean)
End Sub
Sub MAIL(Variable,variable,variable) As ResumableSub
...some code that sets up a mail using smtp...
Wait For SMTP_MessageSent(Success As Boolean)
Return Success
End sub
New video tutorial: Resumable subs is a new feature added in B4J v5.50 / B4i v4.00 / B4A v7.00. It dramatically simplifies the handling of asynchronous tasks. (This feature is a variant of stackless coroutines.) The special feature of resumable subs is that they can be paused, without...
Because you have taken the 'Wait For' out of Big Sub, you have to put one there for each call to Mail (which has to be a resumable sub).
B4X:
Sub BIGSUB
...Lots of code...
Wait For (Mail(some variable, email, etc)) Complete (Success As Boolean)
..More code...
Wait For (Mail(some variable, email, etc)) Complete (Success As Boolean)
..even more code...
Wait For (Mail(some variable, email, etc)) Complete (Success As Boolean)
End Sub
Sub MAIL(Variable,variable,variable) As ResumableSub
...some code that sets up a mail using smtp...
Wait For SMTP_MessageSent(Success As Boolean)
Return Success
End sub
I'll add a tip:
Start writing "complete" in a new line and the IDE will show a list of autocomplete snippets with the Wait For Complete template. I use it a lot.