Skip to content

Commit

Permalink
JS asynchrony cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Aug 26, 2024
1 parent bb650a3 commit 944e9db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions web/src/ferrostar-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ export class FerrostarCore extends LitElement {
}

// TODO: type
async startNavigation(route: any, config: any) {
startNavigation(route: any, config: any) {
// Remove the search box when navigation starts
if (this.useIntegratedSearchBox) this.map?.removeControl(this.searchBox!);

// Initialize the navigation controller
this.locationProvider.updateCallback = this.onLocationUpdated.bind(this);
this.navigationController = new NavigationController(route, config);
this.locationProvider.updateCallback = this.onLocationUpdated.bind(this);

// Initialize the trip state
const startingLocation = this.locationProvider.lastLocation
Expand Down Expand Up @@ -228,7 +228,7 @@ export class FerrostarCore extends LitElement {
this.locationProvider = new BrowserLocationProvider();
}

await this.locationProvider.start();
this.locationProvider.start();

// TODO: Replace this with a promise or callback
while (!this.locationProvider.lastLocation) {
Expand Down Expand Up @@ -256,7 +256,7 @@ export class FerrostarCore extends LitElement {
};

// Start the navigation
await this.startNavigation(route, config);
this.startNavigation(route, config);
}

async stopNavigation() {
Expand Down
4 changes: 2 additions & 2 deletions web/src/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class SimulatedLocationProvider {
}

async start() {
while (true) {
while (this.simulationState !== null) {
await new Promise((resolve) => setTimeout(resolve, (1 / this.warpFactor) * 1000));
const initialState = this.simulationState;
const updatedState = advanceLocationSimulation(initialState);
Expand Down Expand Up @@ -47,7 +47,7 @@ export class BrowserLocationProvider {

updateCallback: () => void = () => {};

async start() {
start() {
if (navigator.geolocation && !this.geolocationWatchId) {
const options = {
enableHighAccuracy: true,
Expand Down

0 comments on commit 944e9db

Please sign in to comment.