If I understand correctly, while the return type of MapFragment1_MarkerClick() is expected to be Boolean, calling a resumableSub within this event (MapFragment1_MarkerClick) requires that the return type of MapFragment1_MarkerClick() to be changed to ResumableSub.
Did I miss anything? How to solve this problem?
B4X:
Sub MapFragment1_MarkerClick (SelectedMarker As Marker) As Boolean 'Return True to consume the click
Wait For(Sum(1, 2)) Complete (Result As Int)
Log("result: " & Result)
Log("after sum")
Return True
End Sub
Sub Sum(a As Int, b As Int) As ResumableSub
Sleep(100)
Log(a + b)
Return a + b
End Sub
Remember the first rule of resumable subs: from the calling method perspective, Wait For and Sleep are equivalent to Return. This means that you cannot call Wait For in a sub that is supposed to return a value (except of the special ResumableSub type).
This means that you cannot call Wait For or Sleep inside this event sub. You can call a resumable sub that will do whatever you need.
Sub MapFragment1_MarkerClick (SelectedMarker As Marker) As Boolean 'Return True to consume the click
AnotherSub
Return True
End Sub
Sub AnotherSub
'Do whatever you like here.
Wait For(Sum(1, 2)) Complete (Result As Int)
End Sub
Sub Sum(a As Int, b As Int) As ResumableSub
Sleep(100)
Log(a + b)
Return a + b
End Sub
Sub MapFragment1_MarkerClick (SelectedMarker As Marker) As Boolean 'Return True to consume the click
AnotherSub
Return True
End Sub
Sub AnotherSub
'Do whatever you like here.
Wait For(Sum(1, 2)) Complete (Result As Int)
End Sub
Sub Sum(a As Int, b As Int) As ResumableSub
Sleep(100)
Log(a + b)
Return a + b
End Sub