안녕 @andrewtkarl , 당신의 제안에 감사드립니다! 귀하의 요청을 접수했으며 검토하겠습니다.
@andrewtkarl , 개발자는 다음을 공유했습니다.
현재 사용자는 JSL 약속을 반환하는 Send(asnyc)와 함께 HTTP 요청을 사용하여 스크립트를 작성할 수 있습니다. 동시 연결이 될 약속 수를 추적할 수 있습니다.
Promise가 완료되면(onResult 또는 onError 포함) 더 많은 요청을 대기열에 추가할 수 있습니다.
다음은 다음에서 공유하는 HTTP 요청 및 JSL 약속을 사용하여 최대 동시 HTTP 요청을 처리하는 예입니다. @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 , 하다 @bryan_boone 의 응답이 이 요청을 충족합니까?
@mia_stephens 네, 그렇습니다. 두 분의 도움에 감사드립니다.
확인 감사합니다 @andrewtkarl .이것을 배달됨으로 표시합니다.
동시 HTTP 호출 수를 제한합니다.
이 같은
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 );
);