0

I have this (extracts):

index.js:

searchSerial: swName => {
    return new Promise(async (resolve) => {
        const url = rawUrl + '?chto=' + swName.replace(' ','+')
        const $ = cheerio.load(await (await fetch(url)).text())
        resolve(new SearchSerial($))
    })
}

SearchSerial.js:

module.exports = class SearchSerial {
constructor($) {

    let key = []

    const secBypass = id => {
        return new Promise(async (resolve) => {
            const url = 'https://www.serials.ws/d.php?n=' + id
            const $ = cheerio.load(await (await fetch(url)).text())
            resolve(new SecBypass($))
        })
    }

    for (let i = 2; i < $("tbody").get(5).children.length-2; i++) {
        let id = parseInt($("tbody").get(5).children[i].children[0].children[0].attribs.href.slice(13,21))
        key.push(secBypass(id))
    }

    this.test = key

}
}

SecBypass:

module.exports = class SecBypass {
    constructor($) {

        this.testing = 'heyyy'

    }
}

But this.test return a list of Promise { <pending> } I've tested many things, read already answered questions but found nothing.

Wxcc
  • 19
  • 10
  • 2
    There is no reason to manually create new `Promise` instances when `fetch` itself returns a promise – Phil Apr 22 '20 at 22:22
  • What do you expect `this.text` to actually be? With `secBypass` returning a promise and `key.push(secBypass(id))` pushing those promises into an array, it should not be surprising that you get an array of promises – Phil Apr 22 '20 at 22:24
  • Ok so what should I do? Something like this? `const secBypass = id => { const url = 'https://www.serials.ws/d.php?n=' + id const $ = cheerio.load(fetch(url)) return new SecBypass($) }`, It's "working" but `$` doesn't contain the right things, for exemple: `this.test = $('body')` return `[initialize]` – Wxcc Apr 22 '20 at 23:10
  • [What is the explicit promise construction antipattern and how do I avoid it?](https://stackoverflow.com/questions/23803743/what-is-the-explicit-promise-construction-antipattern-and-how-do-i-avoid-it) – ggorlen Jan 01 '23 at 03:41

0 Answers0