Похожие чаты

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 ответов

15 просмотров

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

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

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

Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
Мужики и девушки, привет) в Вelphi xe7 в настройках во вкладке "Editor Options" далее " Color" есть список: "Elements", открыв который мы можем настраивать отображение разных...
Kraszx
14
is that okay?
Samurai 🇯🇵
21
Добрый вечер. Есть вопрос, а может и предложение. Был у меня диалог в другой группе о делфи и я задался вопросом: "А нельзя ли в делфи цвет //коментария и {комментария} сде...
Kraszx
24
How about the project bro Likes the community not that active ?
🅿️abby_FX
19
Всем привет! Подскажи, пожалуйста, как передать в TComboBox сразу значение и id записи. На Delphi я делал так: ComboBox1.Items.AddObject('Какое-то значение', Pointer(id запис...
Евгений
13
А вот это что за конструкция? Вернее, она тут нафига?
Serjone
10
Привет. Подскажите, как правильно сматчить лист фиксированного размера, чтобы компилятор не говорил мне о неполном паттерне? Допустим что-то такое [x', y'] = sort [x, y]?
Arseny
8
Мдя, прикол, боевая сборка запускается (именно под отладчиком) после F9 примерно полторы минуты (97 секунд если быть точным). Начал копать - проблема детектится сразу - зависа...
Александр (Rouse_) Багель
38
Is like having a company with great talents, early investors & workers who joined a company but saw that the vision was getting lost so they pushed for a change from within. T...
Randall Roland
2
Карта сайта