synchronizing HTTPRequest events [solved]

Just starting out? Need help? Post your questions and find answers here.
menschmarkus
Posts: 54
Joined: Thu Apr 10, 2014 3:35 pm

synchronizing HTTPRequest events [solved]

Post by menschmarkus »

Hi again,

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.

Following my scheme:

Code: Select all

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.
as soon you do it right, it works !
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: synchronizing HTTPRequest events

Post by Peter »

Code: Select all

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()
menschmarkus
Posts: 54
Joined: Thu Apr 10, 2014 3:35 pm

Re: synchronizing HTTPRequest events

Post by menschmarkus »

Thanks Peter,

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.
as soon you do it right, it works !
Post Reply