due to the fact SB is running asynchronous I face the problem of synchronizing some Events. Unfortunately something like Mutex does not exist in SB.
Hopefully a SB Guru can give me an idea how to solve synchronizing.
procedure httprequest1callback()
;<code>
endprocedure
procedure httprequest2callback()
;<code>
endprocedure
procedure httprequest3callback()
;<code>
endprocedure
procedure GadgetEvents()
select EventGadget()
case #button
HTTPRequest(#PB_HTTP_Get,<url>,"",@httprequest1callback(),0,httpheader()) ;called first
HTTPRequest(#PB_HTTP_Get,<url>,"",@httprequest2callback(),0,httpheader()) ;should be startet after previous call has results
HTTPRequest(#PB_HTTP_Get,<url>,"",@httprequest3callback(),0,httpheader()) ;should be startet after previous call has results
endselect
endprocedure
Procedure main()
BindEvent(#PB_Event_Gadget,@GadgetEvents())
endprocedure
main()
Any Ideas ?
Last edited by menschmarkus on Tue May 14, 2024 4:44 pm, edited 1 time in total.
Procedure httprequest3callback()
;<code>
EndProcedure
Procedure httprequest2callback()
;<code>
HTTPRequest(#PB_HTTP_Get,<url>,"",@httprequest3callback(),0,httpheader()) ;should be startet after previous call has results
EndProcedure
Procedure httprequest1callback()
;<code>
HTTPRequest(#PB_HTTP_Get,<url>,"",@httprequest2callback(),0,httpheader()) ;should be startet after previous call has results
EndProcedure
Procedure GadgetEvents()
Select EventGadget()
Case #button
HTTPRequest(#PB_HTTP_Get,<url>,"",@httprequest1callback(),0,httpheader()) ;called first
EndSelect
EndProcedure
Procedure main()
BindEvent(#PB_Event_Gadget,@GadgetEvents())
EndProcedure
main()
this I already tried but the reply of the HTTP request is too slow.
It runs through without waiting for results.
So I receive a JSON string and store it in a structure. These data are necessary for the second http call.
It happened that the second (and all following) http calls run without having in structure stored information from previous http calls.
I tried with PostEvent() without success but, to be honest, I have no experience with that. Possibly I made it wrong.
[Edit 18:39h]
In the meantime I found a solution. As so often the problem sit in front of the PC.
There was a malformed HTTP call in URL so no result came back. As result it was not working.
So I tried call within procedure with proper HTTP call again and now it works synchronized as wanted.