Closed sonygod closed 4 years ago
Can you give an example? I'm not sure what you want to do
Usually async code is mapped to js promises so you can normally interact with it without the async await keywords
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080 }); await page.goto('https://www.qikegu.com'); await page.waitForSelector('title');
// 截屏页面中的一个区域 await page.screenshot({ path: 'screenshot.jpg', type: 'jpeg', quality: 80, clip: { x: 0, y: 0, width: 300, height: 300 } });
await browser.close();})();
On Sat, 26 Sep 2020, 19:33 George Corney, notifications@github.com wrote:
Can you give an example? I'm not sure what you want to do
Usually async code is mapped to js promises so you can normally interact with it without the async await keywords
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/haxiomic/dts2hx/issues/52#issuecomment-699483484, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFWWIBW2DO3WBH7KFL5TL3SHXGSLANCNFSM4R2Y4XCA .
Haxe native async features are still in development, however in the meantime you can use libraries like https://github.com/haxetink/tink_await to add async/await keywords
If you don't want to use libraries then since the await methods return promises, you can do:
puppeteer.launch().then(browser -> {
browser.newPage().then(page -> {
// rest of code
});
});
or without nested callbacks
Promise.all([puppeteer.launch(), browser.newPage()]).then(array -> {
var browser = array[0];
var page = array[1];
});
package;
import Puppeteer;
import puppeteer.devices.*;
import puppeteer.Browser;
using tink.CoreApi;
@await
class Main {
@async
public static function main() {
var browser:Browser = @await Puppeteer.launch({headless: false, devtools: true}).toPromise();
var page=@await browser.newPage().toPromise();
}
}
support puppeteer?
there is some async don't know how to write in haxe.