for (const proxy of data) {
const kaynak = [];
const func = async () => {
let content = await arrow(proxy); //await ve then aynı anda kullanılmamalı. await zaten async fonksiyon çalışırken kodu bekletmeyi ve return'u değişkene atayabilmenizi sağlıyor.
return content
}
let asd = await func(); // func fonksiyonu async olduğu için await ile bekleyip değişkene atamanız gerekiyor.
console.log(asd) ;
}Aşağıdaki şekillerde de kullanılabilir.
const func = async () => {
return arrow(proxy);
}
func().then(data => { console.log(data); });
aşağıdaki kodlar çalışıyor istediğim veriyi getiriyor ancak döngü durmuyor görev yöneticisinden ağ kullanımına baktığımda hala isteklerin yapıldığını görüyorum.
const arrow = async (proxy) => {
return await new Promise(function(resolve, reject) {
var agent = new HttpsProxyAgent('http://'+proxy)
var proxyRequest = request.defaults({
agent: agent,
timeout: 5000,
headers: {
'user-agent': 'xxxxx'
}
})
proxyRequest.get("xxxx", async function (error, response, body) {
if(!error) {
if(response.body.includes("Your file is ready")) {
resolve(body)
}
}
})
})
}
function getData(data) {
return new Promise( function(resolve, reject) {
data.forEach(async (proxy, index) => {
let content = await arrow(proxy)
if(content.includes("Your file is ready")) {
resolve(content)
}
})
})
}
(async () => {
let proxies = fs.readFileSync("proxies.txt", {encoding:'utf8', flag:'r'}).split(/\r?\n/)
const subContent = await getData(proxies)
console.log(subContent)
})()