B4J Question RuntimeException: Resumable sub already completed - Websocket

juventino883

Member
Licensed User
Longtime User
Hi, I'm having a problem with Wait for, the code works in release mode on my computer, but when I have tried to run it on my server I got this error:

B4X:
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Resumable sub already completed
May 22 12:07:22 uerca01 java[14030]:         at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:496)
May 22 12:07:22 uerca01 java[14030]:         at anywheresoftware.b4a.keywords.Common.access$0(Common.java:467)
May 22 12:07:22 uerca01 java[14030]:         at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:541)
May 22 12:07:22 uerca01 java[14030]:         at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
May 22 12:07:22 uerca01 java[14030]:         at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
May 22 12:07:22 uerca01 java[14030]:         at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:191)
May 22 12:07:22 uerca01 java[14030]:         at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
May 22 12:07:22 uerca01 java[14030]:         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
May 22 12:07:22 uerca01 java[14030]:         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
May 22 12:07:22 uerca01 java[14030]:         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
May 22 12:07:22 uerca01 java[14030]:         at java.base/java.lang.Thread.run(Thread.java:834)
May 22 12:07:22 uerca01 java[14030]: Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Resumable sub already completed
May 22 12:07:22 uerca01 java[14030]:         at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
May 22 12:07:22 uerca01 java[14030]:         at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487)
May 22 12:07:22 uerca01 java[14030]:         ... 10 more
May 22 12:07:22 uerca01 java[14030]: Caused by: java.lang.RuntimeException: Resumable sub already completed
May 22 12:07:22 uerca01 java[14030]:         at anywheresoftware.b4a.keywords.Common.WaitFor(Common.java:1041)
May 22 12:07:22 uerca01 java[14030]:         at b4j.example.estado_de_cuenta$ResumableSub_TOTAL.resume(estado_de_cuenta.java:1967)
May 22 12:07:22 uerca01 java[14030]:         at b4j.example.estado_de_cuenta._total(estado_de_cuenta.java:1907)
May 22 12:07:22 uerca01 java[14030]:         at b4j.example.estado_de_cuenta$ResumableSub_GetTransacciones.resume(estado_de_cuenta.java:1135)
May 22 12:07:22 uerca01 java[14030]:         at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:136)
May 22 12:07:22 uerca01 java[14030]:         at anywheresoftware.b4a.BA.raiseEvent2(BA.java:85)
May 22 12:07:22 uerca01 java[14030]:         ... 11 more

I'm calling the waith for from a websocket class using
B4X:
wait for (organiza_pagos(res)) complete (map_pagos As Map)

and the sub code is this:

B4X:
Sub organiza_pagos (res As DBResult) As ResumableSub
    Dim map_pagos, map_deudas As Map
    map_pagos.Initialize
    map_deudas.Initialize
    
    
    For Each row() As Object In res.Rows   'crea los maps pagos y deudas
                
        Dim x As Int =0
        Dim tipo_transaccion As String
        Dim numero_transaccion As Int
        For Each record As Object In row
            x=x+1
            If x=1 Then 'numero transaccion
                numero_transaccion=record
            End If
            If x=5 Then 'tipo
                tipo_transaccion=record
            End If
            
            If x=7 Then 'monto USD
                If tipo_transaccion = "PAGO" Then
                    If map_pagos.ContainsKey(numero_transaccion) Then
                    Else
                        Dim p As pagos
                        p.Initialize
                        p.monto_tot=record
                        p.restante=record
                        p.mensualidades=""
                        map_pagos.Put(numero_transaccion,p)
                    End If
                Else
                    If map_deudas.ContainsKey(numero_transaccion) Then
                    Else
                        map_deudas.Put(numero_transaccion,record)
                    End If
                End If
                
            End If
        Next
        
    Next
    Log("MAP PAGOS ANTES    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
    Log(map_pagos)
    Log("MAP DEUDAS ANTES    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
    Log(map_deudas)
    For i=0 To map_deudas.Size-1
        Dim trans_D As Int = map_deudas.GetKeyAt(i)
        Dim Monto_D As Double =map_deudas.Get(trans_D)
        
            For Each Trans_P As Int In map_pagos.Keys
                Dim p As pagos
                p.Initialize
                p=map_pagos.Get(Trans_P)
                Dim monto_pago As Double = p.monto_tot
                Dim restante_pago As Double = p.restante
                Dim desc_pago As String = p.mensualidades
                If restante_pago>0 Then
                    If Monto_D>0 Then
                        If Monto_D < restante_pago Then
                            restante_pago=restante_pago-Monto_D
                            p.restante=restante_pago
                        desc_pago=desc_pago&" [("&NumberFormat2(Monto_D,1,2,2,True)&"$) "&trans_D&"]"
                            p.mensualidades= desc_pago
                            Monto_D=0                       
                        Else 'monto_D> restante_pago
                            Dim diferencia As Double = Monto_D-restante_pago
                            desc_pago=desc_pago&" [("&NumberFormat2(restante_pago,1,2,2,True)&"$) "&trans_D&"]"
                            p.mensualidades=desc_pago
                            p.restante=0
                            Monto_D=diferencia
                        End If
                    map_pagos.Put(Trans_P,p)
                    End If
                End If
            
            Next

        
        
    Next
    Log("MAP PAGOS    DESPUES    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
    Log(map_pagos)
    Log("MAP DEUDAS    DESPUES    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
    Log(map_deudas)
    Return map_pagos
    
End Sub

Sincerelly I don't know if I'm not using the wait for instruction correctly (in the case for websockets) or if it could be a bug? If someone can bringme some light here I will be very greatfull!.

greetings
 

OliverA

Expert
Licensed User
Longtime User
Why is the sub declared Resumable? There are no Wait For/Sleep statements in the sub. As it stands, instead of
B4X:
Sub organiza_pagos (res As DBResult) As ResumableSub
you can just do
B4X:
Sub organiza_pagos (res As DBResult) As Map
And then, instead of
B4X:
wait for (organiza_pagos(res)) complete (map_pagos As Map)
do
B4X:
Dim map_pagos As Map = organiza_pagos(res)
 
Upvote 0

juventino883

Member
Licensed User
Longtime User
Hi Oliver, Thanks for your answer I made those changes and it works!, reading your sugestions, sincerelly I'm asking myself why I have used Wait For šŸ˜… again thanks for your help!
 
Upvote 0
Top