I have tried all the possible ways that I understand in the examples and after the Wait For, it returns to the sub that called it. I already use Wait For in other projects, it always waits for it to finish and returns a result.
Below is the summary of the last thing I did trying to simulate the example link. The complete project in post #1
B4X:
'B4XMainPage
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private spPing As Ping
Private Button1 As Button
End Sub
Public Sub Initialize
B4XPages.GetManager.LogEvents = True
spPing.Initialize(Me, "SPPing")
End Sub
Private Sub SPPing_PingStarted
Log("Ping started")
End Sub
Private Sub SPPing_PingFinished
Log("Ping finished")
End Sub
Private Sub SPPing_PingError(Msg As String)
Log(Msg)
End Sub
Private Sub Button1_Click
spPing.Destination = "google.com"
spPing.Attempts = 1
spPing.Timeout = 200
spPing.Start
If spPing.pingResult.Success Then
'More code here
End If
End Sub
[CODE lang="b4x" title="Ping Class"]Sub Class_Globals
Type tpePing (Success As Boolean, toHost As String, toIP As String, fromDest As String, mapResponse As Map, mapStatistics As Map)
Public pingResult As tpePing
Private Pinger As SimplePing
End Sub
Public Sub Start()
#If B4A
pingResult = B4APing
#Else If B4J
pingResult = B4JPing
#Else If B4I
pingResult = B4IPing
#End If
End Sub
Private Sub B4IPing() As tpePing
pingResult.toHost = Destination
iOSDoPing
Return pingResult
End Sub
Private Sub iOSDoPing()
Dim PingerResult As ResumableSub = PingerDoPing
If PingerResult.IsInitialized And PingerResult.Completed Then
For i = 1 To Attempts
Pinger.Send
Wait For Pinger_PacketSent (SequenceNumber As Int, Success As Boolean)
Log("sent: " & SequenceNumber & ": " & Success)
Sleep(Timeout)
Next
icmp_seq.Put(SequenceNumber.As (Byte), DateTime.Now - dblTStart)
Else
If xui.SubExists(mCallback, mEventName & "_PingError", 1) Then
CallSub2(mCallback, mEventName & "_PingError", LastException)
End If
End If
Pinger.Stop
If xui.SubExists(mCallback, mEventName & "_PingFinished", 0) Then
CallSub(mCallback, mEventName & "_PingFinished")
End If
End Sub
Private Sub PingerDoPing() As ResumableSub
Pinger.Initialize("iOSPing", Destination)
Pinger.Start
Wait For Pinger_Start (Success As Boolean)
'Execution never continues after this line, even with the modification I made based on the shared link of how Wait For/ResumableSub works.
pingResult.Success = Success
Return Success
End Sub[/CODE]
I'm not really understanding where my error is, as I said previously in MsgBox2Async, HttpJob and others, the same thing doesn't happen to me, it works perfectly