Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everybody.
I've been working with SQLiteWinRT library and there's no way I can't implement (the far I know) the equivalence of async operation working in bucles for javascript.
Here is an example:
C#
await db.OpenAsync(SQLiteWinRT.SqliteOpenMode.OpenRead);
var stmt = await db.PrepareStatementAsync(
    "SELECT name FROM sqlite_master WHERE type = 'table'"
);
//this is the part
while ( await stmt.StepAsync() )
{
    string table = stmt.GetTextAt(0);
    this.ViewModel.DatabaseTables.Add(table);
}

I hope to be doing the right question.
Posted
Updated 22-Dec-15 1:34am
v2
Comments
Nathan Minier 22-Dec-15 7:41am    
Have you considered using a Task.WhenAll construction?
Pedro Luis Gil Mora 22-Dec-15 10:18am    
Maybe you didn't understand (or viceversa). The far I know, Task.WhenAll returns a Task when you provide a Task<TResult>[] as parameter. In this case, it's a kind of async iterator which it have to wait for each step results. Is this API available for WinRT???
PD: Sorry for my english, I'm Cuban.
Nathan Minier 22-Dec-15 10:41am    
No worries, just would have been a different design pattern. I'm glad that you were able to resolve your issue.

1 solution

I've found the solution by myself . I hope this can help someone
stmt.stepAsync().then(function(r) {
    if (r) {
        var obj = {}, i = -1;
        while (++i < stmt.columnCount) {
            obj[stmt.getColumnName(i)] = stmt.getTextAt(i);
        }
        arr.push(obj);
        stmt.stepAsync().then(arguments.callee);
    } else {
        console.log(arr);
    }
})
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900