Save endpoint json via Promise Pool

This commit is contained in:
Sam Carlton 2022-02-27 14:03:53 -06:00
parent ac455806e8
commit 88d64f528e

View file

@ -2,6 +2,7 @@ import { dirname } from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import dotenv from 'dotenv' import dotenv from 'dotenv'
import { PromisePool } from '@supercharge/promise-pool'
import buildAppList from './helpers/build-app-list.js' import buildAppList from './helpers/build-app-list.js'
import buildGamesList from './helpers/build-game-list.js' import buildGamesList from './helpers/build-game-list.js'
@ -191,9 +192,11 @@ class BuildLists {
} }
saveApiEndpoints = async function ( listOptions ) { saveApiEndpoints = async function ( listOptions ) {
// Save each enpoint's data
for ( const listEntry of this.lists[listOptions.name] ) {
await PromisePool
.withConcurrency(100)
.for( Array.from( this.lists[listOptions.name] ) )
.process(async ( listEntry, index, pool ) => {
// console.log('listEntry', listEntry) // console.log('listEntry', listEntry)
const { const {
@ -212,7 +215,7 @@ class BuildLists {
if (fs.existsSync(endpointPath)) { if (fs.existsSync(endpointPath)) {
console.log(`Path "${endpointPath}" already exists`) console.log(`Path "${endpointPath}" already exists`)
continue return
} }
// console.log(`Saving endpoint "${endpoint}" to "${endpointPath}"`) // console.log(`Saving endpoint "${endpoint}" to "${endpointPath}"`)
@ -222,7 +225,14 @@ class BuildLists {
// Write the endpoint to JSON // Write the endpoint to JSON
await this.saveToJson( listEntry, endpointPath ) await this.saveToJson( listEntry, endpointPath )
} })
// Save each enpoint's data
// for ( const listEntry of this.lists[listOptions.name] ) {
// }
} }
// Save app lists to JSON // Save app lists to JSON