Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
cómo usar subprocesos y funcionalidad sleep() con node.js

Estoy tratando de aprender node.js después de python y tratando de enhebrar un proceso de ejecución infinita en segundo plano con una sleep() .


principal.js

 const TeleBot = require("telebot"); const fun = require('fun.js'); fun(); //function I want to thread const bot = new TeleBot({ token: "Bot_Token", }); bot.on(["/start", "/hello"], (msg) => { bot.sendMessage(msg.from.id, `Hello ${msg.chat.username}`); }); bot.start();

Vi a algunas personas usando esta función sleep() pero no funcionó

diversión.js

 module.exports = async function fun() { while (1) { await sleep(10000); console.log("I ran"); } }

Error: sleep is not defined

Entonces, probé esto

 const sleep = (waitTimeInMs) => new Promise(resolve => setTimeout(resolve, waitTimeInMs)); module.exports = async function fun() { while (1) { await sleep(10000); console.log("I ran"); } }

Funciona, pero ¿es esta una buena práctica y está bien usarla? Además, ¿alguien puede decirme cómo usar worker-threads para esto?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!