Async/Await Class Constructor

Issue At the moment, I’m attempting to use async/await within a class constructor function. This is so that I can get a custom e-mail tag for an Electron project I’m working on. customElements.define(‘e-mail’, class extends HTMLElement { async constructor() {

Continue reading

Express Async Method in Method

Issue I´m quite new to ExpressJS, so i have a question about my Code. router.post("/create", (req: Request, res: Response) => { pruefungController.create(req, res); }); public async create(req: Request, res: Response): Promise<void> { const pruefung = new Pruefung({ fach: req.body.fach, datum:

Continue reading

Awaiting an async function when using Mongodb in node.js

Issue I am trying to retrieve all documents from a MongoDB cluster. I’ve been searching online and using the async/await keywords and have wrote the following code //Database connection const MongoClient = require(‘mongodb’); const uri = “mongodb+srv://user:password@cluster0-10soy.mongodb.net/test?retryWrites=true&w=majority”; async function GetQuestions()

Continue reading

wait for each element

Issue I need to wait each item, than call another function. await readCSV(filename).then(fileArray => { for (let element of fileArray) { console.log(element) searchItem(element) //<— Wait each element will finish this function() } }) the function of searchItem() is: async function

Continue reading

.then running before data is returned from fetch

Issue I want show_name() to run and then call another function. I don’t understand why show_name().then fails. I’m probably overlooking something. async function show_name() { flights_xml.forEach( (flt, i) => {setTimeout(() => { if (document.getElementById(‘show_dx_name’).checked) { let serial_from_xml = flt.children[7].innerHTML; //

Continue reading

Use async await with Array.map

Issue Given the following code: var arr = [1,2,3,4,5]; var results: number[] = await arr.map(async (item): Promise<number> => { await callAsynchronousOperation(item); return item + 1; }); which produces the following error: TS2322: Type ‘Promise<number>[]’ is not assignable to type ‘number[]’.

Continue reading

Use async await with Array.map

Issue Given the following code: var arr = [1,2,3,4,5]; var results: number[] = await arr.map(async (item): Promise<number> => { await callAsynchronousOperation(item); return item + 1; }); which produces the following error: TS2322: Type ‘Promise<number>[]’ is not assignable to type ‘number[]’.

Continue reading

How to handle async call inside if-condition

Issue given code how to handle async call inside if the condition.not store newname in name and run callback first var xyz = function (data, callback) { try{ pool.query(‘select * from devices’,[1],function(err,result){ if(result.rows[0].name = 12){ pool.query(‘select * from devices’,[12],function(err,result){ result.rows[0].name

Continue reading

How to handle async call inside if-condition

Issue given code how to handle async call inside if the condition.not store newname in name and run callback first var xyz = function (data, callback) { try{ pool.query(‘select * from devices’,[1],function(err,result){ if(result.rows[0].name = 12){ pool.query(‘select * from devices’,[12],function(err,result){ result.rows[0].name

Continue reading