After some consideration, I think this might be cleaner:
int main() { db = Sql.Sql(DBNGURL);
Sql.Promise q1 = db->promise_query("SELECT :bar::INT b", (["bar":3])) ->discard_records(0)->min_records(1); Sql.Promise q2 = db->promise_query("SELECT :foo::INT f", (["foo":4])) ->max_records(12)->discard_records(2); Sql.Promise q3 = db->promise_query("SELECT 3");
array all = ({q1, q2, q3})->future();
all->on_success(lambda (Sql.FutureResult okresp) { werror("#########################Ok result %O %O\n", okresp, okresp->data); }); all->on_failure(lambda (Sql.FutureResult okresp) { werror("##########################Failed result %O\n", okresp); }); return -1; }
Notice that I now return a Sql.Promise object, which can be further chained with ->min_records(int min) // Fail when you get less ->max_records(int max) // Fail when you get more ->discard_records(int over) // Do not store more than "over" ->future() // See the future
As far as actual implementations are concerned: I can vouch for the pgsql driver that it starts running the queries in the background in parallel as soon as each of the promise_query()s have been issued.
The other drivers will probably result in the queries running blocking and one at a time. Then again, there is nothing keeping you from using different db connections for each promise.
As far as naming the method is concerned, one could argue if it's supposed to be query_promise() or promise_query(). Any preferences?