Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sleep(time) {
- return new Promise(resolve => setTimeout(resolve, time));
- }
- const page = new Object();
- page.listeners = [];
- page.on = async function (callback) {
- page.listeners.push(callback);
- }
- page.fire = async function () {
- page.listeners.forEach(async element => {
- await element("msg");
- });
- }
- async function eval(callback) {
- return await callback();
- }
- work = async () => {
- await page.on(async (msg) => {
- if (msg === "msg") {
- const val = await eval(function () {
- throw new Error("wrong");
- });
- }
- });
- await sleep(2000);
- await page.fire();
- }
- (async function () {
- try {
- await work();
- } catch (e) {
- console.log(e);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement