Skip to content

Commit

Permalink
implement queue for travel time promises
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed Jul 11, 2024
1 parent aba76c4 commit b90a323
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
32 changes: 32 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@mui/material": "5.x",
"express": "^4.18.2",
"leaflet": "^1.9.4",
"p-queue": "^8.0.1",
"react": "18.x",
"react-calendar": "^4.6.1",
"react-date-picker": "^8.4.0",
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/spatialData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { Days } from './days.js'
import { HolidayOption } from './holidayOption.js'
import { TravelTimeQuery } from './travelTimeQuery.js'
import { domain } from './domain.js'
import PQueue from 'p-queue'

const queue = new PQueue({concurrency: 3})

// instantiated once, this is the data store for all spatial and temporal data
export class SpatialData {
Expand Down Expand Up @@ -116,10 +119,10 @@ export class SpatialData {
return [...this.#queries.values()].sort((a,b)=> a.URI < b.URI ? -1 : 1)
}
fetchAllResults(){
return Promise.all(
return queue.addAll(
this.travelTimeQueries
.filter( TTQ => ! TTQ.hasData )
.map( TTQ => TTQ.fetchData() )
.map( TTQ => () => TTQ.fetchData() )
)
}
}

0 comments on commit b90a323

Please sign in to comment.