Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
Array's of promises pending not sure how to handle

I have tried the usual Promise.all but I get a circular Json error. I have the following promises in my console

all [ Promise { <pending> }, Promise { <pending> } ]
all [ Promise { <pending> } ]
all [ Promise { <pending> } ]
all [ Promise { <pending> } ]

With the following code

const needle = require("needle");

const token = process.env.BEARER_TOKEN_TWITTER;

const endpointUrl = "https://api.twitter.com/2/tweets/search/recent";

export default async function login(req, res) {
  try {
    

    const all = req.body.map((item) => {
      const params = {
        query: `"$${item.title}" from:${item.twitter}`,
      };

      return needle("get", endpointUrl, params, {
        headers: {
          "User-Agent": "v2FullArchiveJS",
          authorization: `Bearer ${token}`,
        },
      }).catch((err) => {
        console.warn(err);
      });
    });


    console.log("all", all);
    // Update
    console.log("allll", await Promise.all(all));


    const result = await Promise.all(all);

    res.status(200).json({ authenticated: true, result: result });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
}

I have read the following with no luck

How to do promise.all for array of array of promises?

Front End Call

const fetchData = async () => {
      const response = newArray.map(
        async (question) => {
          console.log("question", question.data);
          return await fetchTweets(question.data);
        }
      );

      console.log("response", response);


      
      const promise4all = await Promise.all(
        response
        );
        console.log("promise4all", promise4all);
      // setTweets(await Promise.all(response));
    };

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Had to do the following

const needle = require("needle");

const token = process.env.BEARER_TOKEN_TWITTER;

const endpointUrl = "https://api.twitter.com/2/tweets/search/recent";

export default async function login(req, res) {
  try {
    const all = req.body.map((item) => {
      const params = {
        query: `"$${item.title}" from:${item.twitter}`,
      };

      return needle("get", endpointUrl, params, {
        headers: {
          "User-Agent": "v2FullArchiveJS",
          authorization: `Bearer ${token}`,
        },
      }).then(function (response) {
        return response.body;
      });
    });


    const result = Promise.all(all);


    res.status(200).json({ authenticated: true, result: await result });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
}

front end

useEffect(() => {
    // declare the async data fetching function
    const fetchData = async () => {
      const response = newArray.map(
        async (question) => {
          console.log("question", question.data);
          return await fetchTweets(question.data);
        }
      );

      setTweets(await Promise.all(response));
    };

    if (data) {
      fetchData();
    }

  }, [data]);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda