Synchronizing procedures

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

Synchronizing procedures

Post by menschmarkus »

Hi @ all

I am wondering how I can synchronize procedures especially automated httprequests.
Following a schematic code:

Code: Select all

Procedure HttpGetEventCSV(success,result$,userdata)
    If success
    	<do whatever you want with result$>
    EndIf
EndProcedure

Procedure ReadFileCallback()
    protected nblines.i, i.i
    <read file content process here >
    For i = 1 To nblines
    	HTTPRequest(#PB_HTTP_GET,<url incl actual line information>,"",@HttpGetEventCSV(),i)
    next
EndProcedure

Procedure CSVFileRequesterCallback()
    If NextSelectedFile()
        OpenFile(#file,SelectedFileID(),@ReadFileCallback(),#pb_LocalFile)
    EndIf
EndProcedure

Procedure openFileEvent()
    openFileRequester("text/csv",@CSVFileRequesterCallback())
EndProcedure

Procedure main()
    openFileEvent()
EndProcedure

main()
OK, The ReadFileCallback() is much faster than the called HTTPGetEventCSV() so the ReadFileCallback() always fires requests. The delay for the reply of the HTTPGetEventCSV() is 0.5 to 1 second.
My questions are
1. Does this construct cause a possible DoS attack created by myself at a high quantity of requests (e.g. 100 users work at the same time with csv files having 100000 lines in CSV file ? (personally I would say yes)
2. How can I synchronize this construct so a new request of ReadFileCallback() will be releases earliest the HTTPGetEventCSV() has sent the result

Further samples are welcome.

Edit: 24.06.2024 (Comment extension)
It seems to be a hard problem !? :o
Is the problem explanation not clear?
as soon you do it right, it works !
menschmarkus
Posts: 54
Joined: Thu Apr 10, 2014 3:35 pm

Re: Synchronizing procedures

Post by menschmarkus »

Ok, several tests has shown that there seems no solution in SB.
Further researches have shown that the problem propably can be solved in js with "async function" in combination with "await" could solve such a problem.
sample js code:

Code: Select all

// Defines a delay function which returns a Promise
function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

// An asynchronous function which handles the critical part
async function safeProcedure(name) {
    console.log(`Starts the secure procedure ${name}`);
    await delay(2000); // Simulates the time consuming process
    console.log(`End of secure procedure ${name}`);
}

// Control funtion which controls the procedure sequence
async function controlProcedure() {
    await safeProcedure("1");
    await safeProcedure("2");
}

// Call of control procedure
controlProcedure();
Unfortunately I have no experience with inline js in SB so I do not know how to catch the returnvalue of the js delay() function and handle it in SB code.

Any assistance in here?
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 procedures

Post by Peter »

Not directly a solution to your current problem, but personally I would send the files to the server as a whole instead of sending the data line by line.
Post Reply