How to use the p-iteration.forEach function in p-iteration

To help you get started, we’ve selected a few p-iteration examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fractal-code / meteor-azure / source / lib / azure.js View on Github external
static async forEachSite(sites, run) {
    await forEachParallel(sites, async (site) => {
      try {
        await run(site);
      } catch (error) {
        // Attach relevant site context to error
        throw new Error(`${site.uniqueName}: ${error.message}`);
      }
    });
  }
github mprove-io / mprove / src / models / report / fetch-bq-views.ts View on Github external
await forEach(item.dashboards, async (x: interfaces.Dashboard) => {
    // item.dashboards.forEach(x => {

    let newReports: interfaces.Report[] = [];

    await forEach(x.reports, async (report: interfaces.Report) => {
      // x.reports.forEach(report => {

      let model = item.models.find(m => m.name === report.model);

      let filters: { [filter: string]: string[] } = {};

      if (typeof report.filters !== 'undefined' && report.filters !== null) {
        Object.keys(report.filters).forEach(filter => {
          // remove empty filters
          if (report.filters[filter].length > 0) {
            filters[filter] = report.filters[filter];
          }
        });
      }

      let resItem: interfaces.ItemGenBqViews = await genSql.genBqViews({
github mprove-io / mprove / src / models / report / fetch-bq-views.ts View on Github external
export async function fetchBqViews(item: {
  dashboards: interfaces.Dashboard[];
  models: interfaces.Model[];
  udfs: interfaces.Udf[];
  weekStart: api.ProjectWeekStartEnum;
  bqProject: string;
  projectId: string;
  structId: string;
}) {
  await forEach(item.dashboards, async (x: interfaces.Dashboard) => {
    // item.dashboards.forEach(x => {

    let newReports: interfaces.Report[] = [];

    await forEach(x.reports, async (report: interfaces.Report) => {
      // x.reports.forEach(report => {

      let model = item.models.find(m => m.name === report.model);

      let filters: { [filter: string]: string[] } = {};

      if (typeof report.filters !== 'undefined' && report.filters !== null) {
        Object.keys(report.filters).forEach(filter => {
          // remove empty filters
          if (report.filters[filter].length > 0) {
            filters[filter] = report.filters[filter];
github bulwark-crypto / bulwark-explorer / cron / masternode.js View on Github external
async function syncMasternode() {
  const date = moment().utc().startOf('minute').toDate();

  await Masternode.remove({});

  // Increase the timeout for masternode.
  rpc.timeout(10000); // 10 secs

  const mns = await rpc.call('masternode', ['list']);
  const inserts = [];
  await forEach(mns, async (mn) => {
    const masternode = new Masternode({
      active: mn.activetime,
      addr: mn.addr,
      createdAt: date,
      lastAt: new Date(mn.lastseen * 1000),
      lastPaidAt: new Date(mn.lastpaid * 1000),
      network: mn.network,
      rank: mn.rank,
      status: mn.status,
      txHash: mn.txhash,
      txOutIdx: mn.outidx,
      ver: mn.version
    });

    inserts.push(masternode);
  });
github mprove-io / mprove / backend / src / models / proc / split-chunk.ts View on Github external
if (payload.user) {
          // in case if chunk has several changes about same user_id, should not be

          if (payload.user.server_ts < newUser.server_ts) {
            payload.user = newUser;
          }
        } else {
          payload.user = newUser;
        }
      }
    });

    // projects

    await forEach(content.projects, async project => {
      if (isDifferentSession) {
        let projectMemberIds = projectIdToMembersMap[project.project_id].map(
          x => x.member_id
        );

        if (
          projectMemberIds &&
          projectMemberIds.indexOf(wsClient.user_id) > -1
        ) {
          let wrappedProject = wrapper.wrapToApiProject(project);
          payload.projects.push(wrappedProject);
        }
      }
    }).catch(e => helper.reThrow(e, enums.otherErrorsEnum.FOR_EACH));

    // repos
github mprove-io / mprove / backend / src / models / proc / split-chunk.ts View on Github external
let wrappedError = wrapper.wrapToApiError(error);
            payload.errors.push(wrappedError);
          }
        } else if (error.repo_id === wsClient.user_id) {
          // error of user dev repo
          let wrappedError = wrapper.wrapToApiError(error);
          payload.errors.push(wrappedError);
        } else {
          // error of other user dev repo - ok
        }
      }
    }).catch(e => helper.reThrow(e, enums.otherErrorsEnum.FOR_EACH));

    // members

    await forEach(content.members, async member => {
      if (isDifferentSession) {
        let projectMemberIds = projectIdToMembersMap[member.project_id].map(
          x => x.member_id
        );

        if (
          projectMemberIds &&
          projectMemberIds.indexOf(wsClient.user_id) > -1
        ) {
          let wrappedMember = wrapper.wrapToApiMember(member);
          payload.members.push(wrappedMember);
        }
      }
    }).catch(e => helper.reThrow(e, enums.otherErrorsEnum.FOR_EACH));

    //
github mprove-io / mprove / backend / src / models / proc / split-chunk.ts View on Github external
let wrappedRepo = wrapper.wrapToApiRepo(repo);
            payload.repos.push(wrappedRepo);
          }
        } else if (repo.repo_id === wsClient.user_id) {
          // user dev repo
          let wrappedRepo = wrapper.wrapToApiRepo(repo);
          payload.repos.push(wrappedRepo);
        } else {
          // other user dev repo - ok
        }
      }
    }).catch(e => helper.reThrow(e, enums.otherErrorsEnum.FOR_EACH));

    // files

    await forEach(content.files, async file => {
      if (isDifferentSession) {
        if (file.repo_id === constants.PROD_REPO_ID) {
          // file of prod repo
          let projectMemberIds = projectIdToMembersMap[file.project_id].map(
            x => x.member_id
          );

          if (
            projectMemberIds &&
            projectMemberIds.indexOf(wsClient.user_id) > -1
          ) {
            let wrappedFile = wrapper.wrapToApiFile(file);
            payload.files.push(wrappedFile);
          }
        } else if (file.repo_id === wsClient.user_id) {
          // file of user dev repo
github mprove-io / mprove / backend / src / models / proc / split-chunk.ts View on Github external
} else {
          // file of other user dev repo - ok
        }
      }
    }).catch(e => helper.reThrow(e, enums.otherErrorsEnum.FOR_EACH));

    // queries

    await forEach(content.queries, async query => {
      let wrappedQuery = wrapper.wrapToApiQuery(query);
      payload.queries.push(wrappedQuery);
    }).catch(e => helper.reThrow(e, enums.otherErrorsEnum.FOR_EACH));

    // models

    await forEach(content.models, async model => {
      if (isDifferentSession) {
        if (model.repo_id === constants.PROD_REPO_ID) {
          let projectMemberIds = projectIdToMembersMap[model.project_id].map(
            x => x.member_id
          );

          if (
            projectMemberIds &&
            projectMemberIds.indexOf(wsClient.user_id) > -1
          ) {
            // model of prod repo && user is member
            let wrappedModel = wrapper.wrapToApiModel(model);
            payload.models.push(wrappedModel);
          }
        } else if (model.repo_id === wsClient.user_id) {
          // model of user dev repo
github mprove-io / mprove / backend / src / models / proc / split-chunk.ts View on Github external
let wrappedDashboard = wrapper.wrapToApiDashboard(dashboard);
            payload.dashboards.push(wrappedDashboard);
          }
        } else if (dashboard.repo_id === wsClient.user_id) {
          // dashboard of user dev repo
          let wrappedDashboard = wrapper.wrapToApiDashboard(dashboard);
          payload.dashboards.push(wrappedDashboard);
        } else {
          // dashboard of other user dev repo - ok
        }
      }
    }).catch(e => helper.reThrow(e, enums.otherErrorsEnum.FOR_EACH));

    // mconfigs

    await forEach(content.mconfigs, async mconfig => {
      if (isDifferentSession) {
        if (mconfig.repo_id === constants.PROD_REPO_ID) {
          let projectMemberIds = projectIdToMembersMap[mconfig.project_id].map(
            x => x.member_id
          );

          if (
            projectMemberIds &&
            projectMemberIds.indexOf(wsClient.user_id) > -1
          ) {
            // mconfig of prod repo && user is member
            let wrappedMconfig = wrapper.wrapToApiMconfig(mconfig);
            payload.mconfigs.push(wrappedMconfig);
          }
        } else if (mconfig.repo_id === wsClient.user_id) {
          // mconfig of user dev repo
github algolia / talksearch-scraper / src / youtube.js View on Github external
async getVideosFromApi() {
    const config = globals.config();
    const configName = globals.configName();
    const playlists = config.playlists;

    pulse.emit('youtube:crawling:start', { playlists });

    const allVideos = [];
    await forEach(playlists, async playlistId => {
      const videos = await this.getVideosFromPlaylist(playlistId);

      await fileutils.writeJson(
        `./cache/${configName}/youtube/${playlistId}.json`,
        videos
      );

      allVideos.push(videos);
    });

    pulse.emit('youtube:crawling:end');
    return _.flatten(allVideos);
  },

p-iteration

Make array iteration easy when using async/await and Promises

MIT
Latest version published 6 years ago

Package Health Score

65 / 100
Full package analysis

Popular p-iteration functions