B4J Question Server Filter and Wait For

Alexander Stolte

Expert
Licensed User
Can you use wait for in a server filter? Because if I do it like described here in the tutorial, I have no possibility to return in the "filter" sub?

B4X:
Public Sub Filter(req As ServletRequest, resp As ServletResponse)

VerifyToken(req.GetHeader("Authorization"),req) 'Return?
StartMessageLoop

End Sub

Private Sub VerifyToken(auth_token As String,req As ServletRequest) As ResumableSub

fs.VerifyToken(auth_token)
Wait For fs_TokenVerified(TokenId As String, Success As Boolean, Token As FirebaseToken)
Return Success

End sub
 

OliverA

Expert
Licensed User
Something like:
B4X:
Public Sub Filter(req As ServletRequest, resp As ServletResponse)
    dim result(1) as object
    result(0)  = False
    VerifyToken(req.GetHeader("Authorization"),req, result) 'Return?
    StartMessageLoop
    return result(0)
End Sub

Private Sub VerifyToken(auth_token As String,req As ServletRequest, result() as object) As ResumableSub

    fs.VerifyToken(auth_token)
    Wait For fs_TokenVerified(TokenId As String, Success As Boolean, Token As FirebaseToken)
    result(0) = Success
    StopMessageLoop
    Return Success

End Sub
[code]
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
No.

Remember the number #1 rule of resumable subs:
From the caller point of view, the sub returns on the first call to Wait For or Sleep.

This is why you cannot return results from resumable subs without the special ResumableSub type (which must be called with Wait For and is not relevant here).
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User

Attachments

  • FilterWithWaitFor.zip
    2.2 KB · Views: 82
Upvote 0
Top