B4J Question Resumable sub already completed

Blueforcer

Well-Known Member
Licensed User
Longtime User
im still fighting for many days to solve this problem. Unfortunally i dont know how :(. Maybe someone can help me
Im getting following error:

B4X:
Caused by: java.lang.RuntimeException: Resumable sub already completed
    at anywheresoftware.b4a.keywords.Common.WaitFor(Common.java:1041)
    at de.awtrix.main$ResumableSub_processPlugins.resume(main.java:2126)
    at de.awtrix.main._processplugins(main.java:2096)
    at de.awtrix.main._plugin_pluginschanged(main.java:1908)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)

this are the subs:
B4X:
Sub plugin_PluginsChanged 'Event from PluginLib
    If Matrix.isConnected=False Then Return
    processPlugins
End Sub

Sub processPlugins
    tickTimer.Enabled=False
    appTimer.Enabled=False
    pluginList.Clear
    pluginList= plugin.GetAvailablePlugins
    pluginList.Sort(True)
    wait for (oAuthHelper.Initialize) complete
    polling.getPollApps
    reloadPlugins
    refreshApplist
    Wait For (updateAll) complete
    If firstTime Then
        firstTime =False
        logger.write("-----------------------------")
        logger.write("Awtrix Ready - Start")
        logger.write("-----------------------------")
        If Not(Helper.offlineMode) Then updateTimer.Enabled=True
        appTimer.Enabled=True
        AppTimerRunning=True
        ChangeApp(0,"",False)
    End If
End Sub
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Tricky without being able to test it, but I think that the resumable subs you are waiting for need to return a value to fire the complete event. Even if it's a dummy value.

So the wait for calls should be similar to:

B4X:
Wait For (updateAll) Complete (Resp as Boolean) ' or whatever value you want to return as a dummy

Then the updateall (and other resumable subs) need to have a signature of

B4X:
Sub updateAll As ResumableSub

'
'
'
    Return True ' when complete'
End Sub

Try that and see if it helps

[edit}

In fact a little more testing shows that it should work if you change the signatures to:

B4X:
Sub updateAll As ResumableSub

And no need to return a value or change the call line, if you already have that signature then it would be useful to upload an example so it can be tested.
 
Last edited:
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
@stevel05 updateAll is already declared as a resumable sub with a return value. i will try to expand the Wait For with a return


@Erel
This is another resumable sub.

B4X:
public Sub Initialize As ResumableSub
    oAuthMap.Initialize
    For Each app In Main.pluginList
        Dim infos As Map = Main.getPluginInfos(app)
        If infos.ContainsKey("oauth") Then
            If infos.get("oauth") Then
                Dim m As Map = infos.get("oauthmap")
                If m.Size=0 Then Return True
                Dim oauthApp As oauthServer
                oauthApp.Initialize(app,m.Get("AuthorizeURL"),m.Get("TokenURL"),m.Get("ClientId"),m.Get("ClientSecret"),m.Get("Scope"))
                oAuthMap.Put(app,oauthApp)
                wait for (Main.updateByName(app)) complete
            End If
        End If
    Next
    Return True
End Sub

I would really like to reduce and upload the project for you, but the project is now so huge and so intertwined that this would only be possible with a lot of work :)
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Yes, its just a code module, not a class.

Wich event do you mean?
I dont use threading.

as @stevel05 mentioned i expand every wait for with (Resp as Boolean) and each resumable sub with a boolean return value.
So far the error has not occurred again. I have to say that it only occurred sporadically, but especially on slow hardware like a raspberry
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The parameter is indeed missing.

Wich event do you mean?
B4X:
Sub plugin_PluginsChanged 'Event from PluginLib

I'm pretty sure that this event is raised from a different thread. This is the problem and it will continue to happen.
Best solution is to ask the library developer to update the library and raise the event on the main thread.
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
@alwaysbusy But this isn't the branch you had made especially for me? You may remember the memory leak and some other new functions:
1581332901265.png


Edit: you was faster ;)
 
Upvote 0
Top