Skip to content

Commit

Permalink
Implement queue for travel time data retrieval (#132)
Browse files Browse the repository at this point in the history
* implement queue for travel time promises

* queue belongs to object
  • Loading branch information
Nate-Wessel authored Jul 12, 2024
1 parent aba76c4 commit 2c2cb3d
Show file tree
Hide file tree
Showing 3 changed files with 37 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
6 changes: 4 additions & 2 deletions frontend/src/spatialData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ 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'

// instantiated once, this is the data store for all spatial and temporal data
export class SpatialData {
#factors = []
#queries = new Map() // store/cache for travelTimeQueries, letting them remember their results if any
#knownHolidays = []
#queue = new PQueue({concurrency: 3})
constructor(){
this.#factors.push(new Days(this))
this.#factors.push(new HolidayOption(this,true))
Expand Down Expand Up @@ -116,10 +118,10 @@ export class SpatialData {
return [...this.#queries.values()].sort((a,b)=> a.URI < b.URI ? -1 : 1)
}
fetchAllResults(){
return Promise.all(
return this.#queue.addAll(
this.travelTimeQueries
.filter( TTQ => ! TTQ.hasData )
.map( TTQ => TTQ.fetchData() )
.map( TTQ => () => TTQ.fetchData() )
)
}
}

0 comments on commit 2c2cb3d

Please sign in to comment.