Usage of d3.sparql


#1

I used d3.sparql and I’m wondering if there is a way to have a synchron behavior. I would like to embed the d3.sparql call into a function and to wait until the “data” result is fed with the SPARQL query result.

Thanks for any tip.

Jean-Luc


#2

The d3.sparql call returns a promise. If you want the calling function to wait you’d either return that promise further or create an async function

async function doWork () {
  const data = await d3.sparql(wikidataUrl, mikeQuery)

  // do something else when sparql has completed
}

Async function is really a promise too. In the calling code you either await doWork() or doWork().then().

Does this help?