Похожие чаты

Hi. What is the best way to make two synchronous functions

that are being called and run one after another, into asynchronous functions?
for instance I have two functions named func1 and func2
and they both print their names on the console
I don't want it to always be func1 and then func2
I know I can make them run asynchronous by using setTimeout
just like this :

setTimeout(() => func1(), 0);
setTimeout(() => func2(), 0);

I'd like to know if there are other ways of doing it cleaner and more appropriate

11 ответов

13 просмотров

You need to edit the logic inside func1 and func2 to make the logic asynchronous

seems like it's ordered even with timeout

Willy- Автор вопроса
Thomas
You need to edit the logic inside func1 and func2 ...

the thing is that these two or more functions are used to inject html code into the DOM, I don't want the whole app to freeze because I call them one after another

Willy
the thing is that these two or more functions are ...

Maybe inside func1 you wait a bit everytime you add something to DOM with a setTimeout

Willy
the thing is that these two or more functions are ...

How much stuff are you adding to the DOM for it to take that much time

Willy- Автор вопроса
Thomas
Maybe inside func1 you wait a bit everytime you ad...

setTimeout fixes the problem all by itself however it makes the code somehow weird and odd

Willy- Автор вопроса
Thomas
Explain

look there is the static part of the app which is gonna be rendered from the server but the rest of app will be loaded from the client using javascript after the DOMContentLoaded event is triggered I'm also thinking of adding an object which has properties which hold true or false depending on the expected parts are loaded or not. and these functions that are meant to load the dynamic parts are going to be called at the very beginning of our DOMContentLoaded handler but the problem shows itself when you realize you can't make them work async by just the way you write the functions, the way they are processed in sync so they stay that way

Похожие вопросы

Обсуждают сегодня

Какой-то там пердун в 90-х решил, что есть какая-то разная типизация. Кого вообще это волнует?
КТ315
49
Hi. Do we have a raid bot? Why nobody doing raids on X? Even RH mentioned this and nobody paying attention...whats the channel for hex memes? If mods cant run raids just insta...
H
31
Подскажите, а есть vault lite или ченить такое?) А то нужен вольт для похода в вольт, но весит он ~500 мб) как-то многовато для парочки запросов ))
Alexandr Orloff
17
блеать, почему так?? где в роутере это исправляется?
Арсен Маньяков 🇦🇲
16
void terminal_scroll() { memmove(terminal_buffer, terminal_buffer + VGA_WIDTH, buffer_size - VGA_WIDTH); memset(terminal_buffer + buffer_size - VGA_WIDTH, 0, VGA_WIDTH); ...
Егор
47
🌊 Ocean Nodes Dashboard Update 🚀 Hey, Oceaners! First off, a massive round of applause 👏to all of you for the amazing engagement since we launched Ocean Nodes. In just a few ...
KreigDK | Never DM first🌊
3
Всем привет! Подскажите, пожалуйста, в чем ошибка? Настраиваю подключение к MySQL. Либы лежат рядом с exe. Все как по "учебнику"
Евгений
16
А можете как-то проверить меня по знаниям по ассемблеру?
A A
132
Здравствуйте! У меня появилась возможность купить книгу "Изучай Haskell во имя добра!". Но я где-то слышал, что эта книга устарела. Насколько это правда??
E
22
люди, которые используют flameshot, к вам вопрос. Можно-ли поставить хоткей на создание скриншота? В программе есть отдел "горячие клавиши", но там все для редактирования, скр...
ThunDer104
11
Карта сайта