B4J Question [BANanoServer] [SOLVED] Future on SERVER and BANanoPromise on BROWSER?

Mashiane

Expert
Licensed User
Longtime User
Ola

Q1.
In your example, BrowserAbout, you have called?

B4X:
Dim prom As BANanoPromise = ws.RunFunctionWithResult("AddOnTheServer", Array(3 , 6))
	prom.Then(value)
		Log("SERVER says sum of 3+6=" & value)
	prom.end

and in ServerAbout, we have


B4X:
	Dim fut As Future = ws.RunFunctionWithResult("AddInTheBrowser", Array(20, 30))
	ws.Flush

Just to be clear. To send stuff from the server to the browser, one always have to use a Future. To process that Future one has to use a BANanoPromise?

Q2. So If I want to get stuff from the server I always have to pull them and JSON and push up JSON?

TheMash
 

alwaysbusy

Expert
Licensed User
Longtime User
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Q2. So If I want to get stuff from the server I always have to pull them and JSON and push up JSON?
There is a pull of data from the server, this is called with

B4X:
Dim humanJson As String
    Dim promHuman As BANanoPromise = ws.RunFunctionWithResult("GetHuman", Null)
    promHuman.Then(humanJson)
        Human.FromJson(humanJson)
        ' making a change
        Human.Name = "Alain Bailleul"
        ' and sending it back to the server
        ws.RunFunction("SetHuman", Array(Human.ToJSON))
        Log("Hello Human " & Human.Name & " (" & Human.Gender & ")")
    promHuman.end

The server pull code is

B4X:
' called from the BROWSER
public Sub GetHuman() As String
    ' make a human that the browser can retrieve
    Human.Name = "Alain"
    Human.Gender = "Male"
    Return Human.ToJSON
End Sub

Also on the server code, for the push

B4X:
' called from the BROWSER
public Sub SetHuman(HumanStr As String)
    Human.FromJson(HumanStr)
    Log("Human.Name (changed in the browser) is " & Human.Name)
End Sub

In both cases, we have .TOJSON and .FromJSON. I see now, I remembered something, the database records (via CallInlinePHP) I was getting were an array of objects, then these were converted into a list.

Thanks, I now understanding, this is not any different from what I have been doing before with inline php, but I dont have to think and use inline php but pure coding to speak to the DB. The beauty of Change Managment.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
On the issue of Flushing, just to be clear, its not necessary on the browser.

On the server, we are flushing..

B4X:
Dim fut As Future = ws.RunFunctionWithResult("AddInTheBrowser", Array(20, 30))
    ws.Flush
    Log("BROWSER says sum of 20+30=" & fut.Value)
   
    ' or if no result is expected back
    ws.RunFunction("BROWSERTest", Array("Hello from the SERVER!"))
    ws.Flush

On the browser, we are not flushing..

B4X:
Dim value As Int = 0
    Dim prom As BANanoPromise = ws.RunFunctionWithResult("AddOnTheServer", Array(3 , 6))
    prom.Then(value)
        Log("SERVER says sum of 3+6=" & value)
    prom.end

Thanks
 
Upvote 0
Top