I'm using mbostock queue.js script to load several json files, by doing something like that:
var q = queue()
.defer(d3.json, "world-110m.json")
.defer(d3.tsv, "world-country-names.tsv")
.await(ready);
where ready is the function to execute when everythin is loaded.
I would like to preload an image by adding a defer. Is this possible? I have tried it several ways, but it doesn't work.
I suppose that a function must be created, but I can't make it asynchronous, and the queue keeps waiting forever...
Here is what queue.js is expecting from the callbacks:
Thus a simple version of your code might look like this:
I'm not sure what (if anything) you wanted to return about the image, but in the above example
cb(null, img)
I'm returning the whole object.