Skip to content

Make greenlet working with a pool of Promises #43

Description

@empav

Hi guys, maybe I'm wrong and need to give it a better look at service workers but what I'm trying to accomplish is the following:

1- I'd like to pass to greenlet an array of promises like the Promise.all(promises) return.
2- Await for them inside the greenlet function.
3- returning the result to the main app.

This is my code:

          try {
            const promises = validationAuto(chunk, workarea, criteria, test_groups); 
            if (window.Worker) {
              validationAutoWorkerized(promises);
            } else {
              await promises;
            }
          } catch (error) {
            console.log(error);
          }
const validationAuto = (chunk, workarea, criteria, test_groups) => {
  const validationPromises = chunk.map(id => {
    return new Promise((resolve, reject) => {
      postWorkareaValidationAuto(workarea, id, criteria, test_groups)
        .then(response => resolve(response))
        .catch(error => reject(error));
    });
  });
  return Promise.all(validationPromises);
};
const validationAutoWorkerized = greenlet(async promises => {
  const data = await promises;
  console.log(data);
  return data;
});

Any tip to accomplish it with greenlet? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions