Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute multiple queries synchronously #326

Closed
mohamednagy opened this issue Apr 23, 2024 · 2 comments
Closed

Execute multiple queries synchronously #326

mohamednagy opened this issue Apr 23, 2024 · 2 comments

Comments

@mohamednagy
Copy link

mohamednagy commented Apr 23, 2024

I'm doing multiple queries to get steps, calories, sleep and heart rates.
I want to execute those queries synchronsously so I can show the user a spinner till all data got retrieved.
How can execute those queries synchronsously ?

@mohamednagy mohamednagy changed the title Execute multiple queries asynchronously Execute multiple queries synchronously Apr 24, 2024
@dariosalvi78
Copy link
Owner

dariosalvi78 commented Apr 24, 2024

what od you mean "synchronously"? Queries are synchronous. If you mean "in parallel", it can't be done. See #294

@BenLaKnet
Copy link

You could serialize queries.

First query starts the spinner in success, you start too the second query and in the last, you stop spinner.

You could try that :



function getSyncDatasSteps(nbjours) {
	
	cordova.plugins.health.queryAggregated({
	  startDate: new Date(new Date().getTime() - (nbjours * 24 * 60 * 60 * 1000)),
	  endDate: new Date(), // now
	  dataType: 'steps',
	  bucket: 'day'
	}, function(data) {
		startSpinner();
                successSyncDatasCB(data);
		getSyncDatasCalories(nbjours);
		
	}, errorCB);
	
}

function getSyncDatasCalories(nbjours) {
	
	cordova.plugins.health.queryAggregated({
	  startDate: new Date(new Date().getTime() - (nbjours * 24 * 60 * 60 * 1000)),
	  endDate: new Date(), // now
	  dataType: 'calories',
	  bucket: 'day'
	}, function(data) {
		successSyncDatasCB(data);
		getSyncDatasGlycemie(nbjours);
	
		
	}, errorCB);

}

function getSyncDatasGlycemie(nbjours) {
	
	cordova.plugins.health.query({
	  startDate: new Date(new Date().getTime() - (nbjours * 24 * 60 * 60 * 1000)),
	  endDate: new Date(), // now
	  dataType: 'blood_glucose',
	  limit: 1000
	}, function(data) {
		
		successSyncDatasCB(data);
	        stopSpinner();
		
	}, errorCB);
}

successSyncDatasCB records all datas in an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants