Open gajus opened 7 years ago
The callback is called for each response.
To answer my own question,
const searchGoogle = (query: string, limit: number = 10) => { return new Promise((resolve, reject) => { const results = []; GoogleSearchScraper.search({ host: 'www.google.com', lang: 'en', limit, query: query + ' site:imdb.com/title/' }, (error, result) => { if (error) { reject(error); } else { results.push(result); if (limit === results.length) { resolve(results); } } }); }); };
However, this will hang if there are no results for the query.
Am I overlooking something?
You're right, another callback should be fired when there are no more results. I'll accept PRs fixing this as long as they are backwards-compatible.
The callback is called for each response.
To answer my own question,
However, this will hang if there are no results for the query.
Am I overlooking something?