0
配列[1,2,3,4]
は2つを取り出して2つのリクエストを送信します。Nodejs以前のロジックが完了したときにロジックを実行する方法
完了したらもう2回、2つの新しいリクエストを作成します。
Nodejsが同期的なので、以下のように私はそれを行うことができません。
var request = require('request');
var args=[1,2,3,4];
function chunk(){...}
args = chunk(args,2); //My custom function to split array into chunks
args.forEach(function(value)
{
value.forEach(function(value_value)
{
/***********sent requests**************/
var options = {
method: 'POST',
url: 'http://dev.site/date.php',
formData: {arguments:value_value}
};
request(options, function (error, response, body)
{
if (body=='hello') {
console.log(body);
}
});
/**************************************/
});
});
あなたがrequest-promise
とq
を使用することができます私に
あなたはサードパーティのモジュールを使いたいと思うので、 'lodash'の' chunk'をお勧めします:http://devdocs.io/lodash~4/index#chunk リクエストを順番に行うために、一度、 'eachSeries'関数で' async'のようなモジュールを調べることをお勧めします:http://caolan.github.io/async/docs.html#.eachSeries – forrert
速い答えのためのthx私は正確に説明していません私はいくつかのロジックを待ってから次のステップに進む必要があります –