당신은 배열을 포함하는 배열 .length
이 true
에 대한 응답의 다른 반환 배열을 평가하는 경우 함수에 전화 예약 Array.prototype.shift()
, .then()
를 사용할 수 있습니다. 프로세스를 순서대로 수행합니다. 순서는 요구 사항의 일부가 아닌 경우
const requests = [[..], [..], [..]];
let results = [];
let request = requests.shift();
let handleRequests = (data) => fetch("/path/to/server", {
method:"POST", body:data
})
.then(response => response.text())
.then(res => {
results.push(res);
return requests.length ? handleRequest(requests.shift()) : results
});
handleRequest(request)
.then(res => console.log(res)
, (err) => console.log(err));
주, 당신은 .shift()
에 대한 Promise.all()
, Array.prototype.map()
을 대체 할 수 있습니다. 감사합니다,하지만 난 배열의 배열에하고 싶어 - superagent``확실하지
let handleRequests = (data) => fetch("/path/to/server", {
method:"POST", body:data
})
.then(response => response.text());
Promise.all(requests.map(handleRequests))
.then(res => console.log(res)
, (err) => console.log(err));
, 당신은 그 때는()가'통화') (가져 오기 '에 체인 – guest271314
guest271314 @'사용할 수 있어야합니다 . 프로그래밍 방식으로이를 수행 할 수있는 방법이 있습니까? –
예, [multiple, sequential fetch() Promise] (http://stackoverflow.com/questions/38034574/multiple-sequential-fetch-promise/)를 참조하십시오. 이 패턴은 "재귀"가 아니라 "일정 잡기"로 간주됩니다. 15 만 건의 요청을 의미합니까? 아니면 세 가지 요청? 요청을 순차적으로 작성해야합니까? – guest271314