I am using rethinkDB with node.js. The following request works fine :
function myFn () {
return co(function *() {
let query;
query = yield r.db("my-db")
.table("app")
.filter(r.row("id").eq(id))
.run(conn);
return query.toArray();
});
}
I would like to return the result of multiple yield
asynchronously, however the following fails :
function myFn () {
return co(function *() {
let query, query2;
query = r.db("my-db")
.table("app")
.filter(r.row("id").eq(id))
.run(conn);
query2 = r.db("my-db")
.table("app")
.filter(...)
.run(conn);
return yield {q1 : query, q2 : query2};
});
}
Then I have to call toArray()
on each element, so on the calling function I do :
// using ramda.js
var res = R.map((el) => {
return el.toArray();
}, yield myFn);
However I get :
{
"q1": {
"isFulfilled": false,
"isRejected": false
},
"q2": {
"isFulfilled": false,
"isRejected": false
}
}
Something odd too :
// this works perfectly
return q.toArray();
// this returns the following :
return {q: q.toArray()};
"q": {
"isFulfilled": true,
"isRejected": false,
"fulfillmentValue": [ ... ]
}
I suspect I am missing something about the way yield
works, so how can I return the fulfilled result of multiple yield
results ?