Query fails with Async Adapters
mattbryson opened this issue · 4 comments
The Query plugin uses an Async method to lookup data, but assumes its Sync, so the where
query returns (and executes callback) before it has actually looked-up any data.
To fix, I moved the setting of this.__results
into the callback of the all
lookup, and trigger the where
callback there.
However, the drawback is that chaining (indicated in the docs) is not possible.
this.all(function(all){ //This is Async, so we have to update __results in the callback...
for (var i = 0, l = all.length; i < l; i++) {
var success = is(all[i]);
if (success) r.push(all[i])
}
// overwrite working results
this.__results = r;
// callback / chain
if (args.length === 1) this.fn(this.name, last).call(this, this.__results)
})
//Chaining wont work as the data loaded into __results is Async, so chained methods will execute before __results is populated
return this
Well heck, I'd been going round in circles trying to figure out why I wasn't getting any query results back - until I stumbled across this issue!
I was debugging where for awhile before stumbling on this issue as well. +1 to get it fixed in master!
@fisch0920, I believe that code was put in the trunk April 24, 2013.
Yep; you're right. I think the real issue here is that the files linked off of http://brian.io/lawnchair/ are way outdated and don't include this fix.