Hi @andrewtkarl, thank you for your suggestion! We have captured your request and will take it under consideration.
@andrewtkarl , the developer shared this:
Currently a user can write a script using HTTP Request with Send(asnyc) that will return a JSL promise. They can track the number of promises, which will be the concurrent connections.
When a promise has finished (with onResult or onError) they can queue up more requests.
Here’s an example of handling the maximum concurrent HTTP Requests using HTTP Request and JSL Promises shared by @bryan_boone :
Names Default To Here( 1 );
//populate the requests
requests = {};
promises = {};
count = 100;
max = 30;
For(i = 1, i <= count, i++,
request = New HTTP Request( //this is the HTTP Request for the Query String Example in the SI
url( "http://httpbin.org/get" ),
Method( "GET" ),
Query String( [["username" => "bob", "address" => "12345", "count"=>i]] )
);
InsertInto(requests, request);
);
//now send them async
process_result = Function( {p, r},
//Show(p);
//Show( r );
if(N Items(promises),
RemoveFrom(promises, 1);
);
);
process_error = Function( {p, e, t},
//Show(p);
//Show( e );
//Show( t );
if(N Items(promises),
RemoveFrom(promises, 1);
);
);
while(N Items(requests),
count = max - N Items(promises);
if(count > N Items(requests),
count = N Items(requests);
);
Show(count);
For(i = 1, i <= count, i++,
request = requests[1];
RemoveFrom(requests, 1);
promise = request << Send( "async" );
InsertInto(promises, promise);
promise << On Result( process_result );
promise << On Error( process_error );
);
If(Nitems(promises),
wait(0);
);
);
//catch any stragglers
while(Nitems(promises),
wait(0);
);
Write("\!nDone!!!\!n");@andrewtkarl , does @bryan_boone's response satisfy this request?
@mia_stephens Yes it does, thank you both for your help.
Thanks for the confirmation @andrewtkarl. Will mark this as delivered.
to limit the number of simultaneous HTTP calls.
Something like this
custom_multi_http = Function( {mm, max = 30},
//mm=multi_http_requests;
//max=5;
res = {};
status = {};
mm_get = mm << get requests;
chunks = Ceiling( N Items( mm_get ) / max );
chunk_list = {};
For( i = 1, i <= chunks, i++,
chunk_i = New Multi HTTP Request();
For( j = 1 + (i - 1) * max, j <= Min( max * i, N Items( mm_get ) ), j++,
chunk_i << Add( mm_get[j] )
);
Wait( 0 );
chunk_i_requests = chunk_i << get requests;
Insert Into( res, chunk_i << Send() );
Insert Into( status, chunk_i_requests << get status() );
);
Return( res, status );
);