So my code is of the "let's use Generators to avoid Callback Hell" variety. I'm trying to have an accessor function wrap a generator that handles opening IndexedDB. I need to have the generator yield to the "callback", and then yield to the accessor function so the accessor function can return the created object which originated in the generator. Maybe this is a brainfart, but I'm kinda lost as to how to do this without polling on a boolean (such as idb_ready = false; and wait for idb_ready to be true before starting the while(gen.next()) business).
Code:
accessor = function() {
var gen = function* () {
var ret = {};
var request = indexedDB.open("blah", 1, "description");
request.onupgradeneeded = resume;
var event = yield;
ret.db_instance = event.target.result;
yield ret;
};
function resume(val) { gen.next(val); }
gen.next(); // start the generator
// HERE is where I need to wait for the second yield
}
Is there a way to do this without polling? Thanks!