Похожие чаты

Hey guys, I want to delay sendTwitterVideo without blocking bot.sendVideo?

18 ответов

13 просмотров

const sleep = ms => new Promise((resolve, reject) => setTimeout(resolve, ms))

Misan
const sleep = ms => new Promise((resolve, reject) ...

Because this doesn't reject, I like to write it shorter like this: const sleep = t => new Promise(r => setTimeout(r, t))

Misan
const sleep = ms => new Promise((resolve, reject) ...

I do this exactly, except without reject.

jc-| 23:33 Автор вопроса
jc | 23:33
This blocks bot.sendVideo

do bot.sendVideo first, then sleep, then rest

jc | 23:33
This blocks bot.sendVideo

setTimeout(() => /* action after x seconds */, x * 1000); // action to be performed right now

jc-| 23:33 Автор вопроса
A​kshit
setTimeout(() => /* action after x seconds */, x *...

Yeah, this blocks sendVideo function itself, doesn't it? I am calling sendVideo inside for of loop, and I need to keep uploading to twitter with 1 minute intervals and to telegram without any delay

A​kshit
setTimeout is non blocking afaik

await sleep(..) will stop the function exection though

jc | 23:33
Yeah, this blocks sendVideo function itself, doesn...

i think you should make a queue for videos to be sent to twitter and you use setInterval to periodaclly check if there are any videos in the queue and send one if there is any

jc-| 23:33 Автор вопроса
Artem Starikov
i think you should make a queue for videos to be s...

Can't I have one general queue for twitter as well as telegram?

jc | 23:33
Can't I have one general queue for twitter as well...

if you can send videos to telegram instantly, you shouldn't need a queue for that

jc-| 23:33 Автор вопроса
Artem Starikov
if you can send videos to telegram instantly, you ...

I collect the videos that weren't sent yet and then send them away

jc | 23:33
Yeah, this blocks sendVideo function itself, doesn...

what you probably want here is const twitterQueue = []; setInterval(() => { const video = twitterQueue.shift(); if (video) { sendTwitterVideo(..); } }, 60 * 1000); const sendVideo = async (..) => { // .. twitterQueue.push(..); };

jc-| 23:33 Автор вопроса

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

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

Hey guys, did you see the new announcement about $Fun? 🔥
Filip Murphy
55
А чем вам питонисты не угодили?😂
.
79
Язык Си можно выучить за день? По книжке ANSI C на 230 страниц
Vincent Vegan
29
Привет, запускаю werf в dind в k8s, получаю ошибку на этапе build/beforeSetup: /.werf/stapel/embedded/bin/bash: /.werf/scripts/5898bdfe5214357d3706b879cc8d3d78460fb379607cbd...
florius0
7
пацаны, как-нибудь можно панель задач заблюрить, что она была похожа на kde или винду 7, 11?
В
16
Всем привет, написал код ниже, но он выдает сегфолт, в чем причина? #include <stdio.h> #include <stdlib.h> #include <string.h> struct product { char *name; float price; };...
buzz базз
75
Dim Dim, [02.07.2024 11:07] DB 0x62 Dim Dim, [02.07.2024 11:07] DB 0x66 Dim Dim, [02.07.2024 11:07] кто пояснит что это?
Dim Dim
14
So total 101m burned Today?
Simu
18
Ошибка: segmentation fault (core dumped) Код: pastebin.com/BEsNNSSV Сообщение от компилятора: отсутствует ОС: Arch Linux Ядро: x86_64 Linux 6.9.7-arch1-1 Процессор: Intel Cele...
sec
4
Hi, I can't understand promises in JavaScript and what we should use them for (maybe the teacher didn't teach well XD). Do you have a solution for this? And are promises used...
A
29
Карта сайта