Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

561
Vistas
DataCloneError: #<Promise> could not be cloned

I am using worker thread in node js, below is my code in two files

worker.js

const mysql = require('mysql2');
const { 
v1: uuidv1,
v4: uuidv4,
} = require('uuid');
const {parentPort, workerData} = require("worker_threads");

const dayjs = require('dayjs');

parentPort.postMessage(getRdvSlots(workerData.data));

async function getRdvSlots(data){
  if(data.duration == 0 || data.address_id.trim() === "" || data.reasonId.trim() === "" || data.people_id.trim() === "" ){
    return false;
  }
  let details = {};

  let startDate = data.sel_date;
  details["startDate"] = startDate;

  let availableDates = await generateAvailableDates(data.people_id, data.address_id, data.reasonId, startDate);

  let emptyAvailabilities = 0;
  let slots = {};
  for(let key in availableDates){
    slots[key] = await getSlots(key, availableDates[key],data.people_id, data.duration);
  }
  details["slots"] = slots;

  return JSON.parse(JSON.stringify(details));
}

And in index.js

app.get("/checkworker", async (req, res) => {
    const worker = new Worker("./worker.js", {workerData: {data: req.query}});

    worker.once("message", result => {
        console.log(`${result}`);
        res.send(result);
    });

    worker.on("error", error => {
        console.log(error);
    });

    worker.on("exit", exitCode => {
        console.log(`It exited with code ${exitCode}`);
    })
});

In this I am getting error of

DataCloneError: # could not be cloned. at Object. \worker.js:10:12

which is at line parentPort.postMessage(getRdvSlots(workerData.data)); in worker.js

I am new to nodejs worker thread any help what is error in my code

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I found this question b/c I had the same issue. I just fixed it :) The object I was trying to post to the other thread had a property an async method was setting. I did not add await to the line :)

I think this will fix your issue:

parentPort.postMessage(await getRdvSlots(workerData.data));
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda