Sdk: Dart 'await' not waiting?

Created on 3 Oct 2016  路  8Comments  路  Source: dart-lang/sdk

I have posted the following question at Stack Overflow. Maybe someone around here has a good idea, what's going on?

http://stackoverflow.com/questions/39820567/dartlang-await-not-waiting?noredirect=1#comment66938127_39820567

I had similar situations before. Maybe this is some bug in dart? Or it's a bug in angular 2 Transformer / dart2js?
Since this is a chrome extension project, I can't debug it in dartium and I have to rely on log messages for debugging.

web-dart2js

Most helpful comment

@kulshekhar I think the entry is added after the first run through the code.
Use indexedDB.deleteDatabase("speedpadDB") to clear the database and start fresh.

All 8 comments

Do you have a repro?
It would be much easier for us to debug this, if we could run it on our machines.

Okay, no problem.

https://bitbucket.org/bjesuiter/chrome-speedpad

This repo was private before, so I will add a Readme later this day.

For your testing, please use the upgrade_extension_to_angular_2 branch.

When you run pub build, you can add the web folder in build as extracted extension to Chrome and open a new tab page with dev tools for log messages :-)

if (stringData == null) {
    _log.finest("No Structure saved in database - create default structure");
    List<TabEntry> structure = [];
    structure.add(new TabEntry("Home"));

    //All things are working till here

    //Problem: Create key in db - this apparently does not wait 
    String key = await _db.save(serializeToJson(structure), "structure");
    .
    .
}

Why does await _db.save(serializeToJson(structure), "structure") not wait?

I did a quick test and it doesn't look like stringData is null, so the line in question is not executed. Here's the value for stringData that I got:

{"rules":null,"data":[[],[[{"__Ref":0,"rule":5,"object":0}]],[],[],[],[{"filename":"70f8bb9a8a5393ef080507a89e4b98d139000d65","usesImage":false,"entryType":"SpeedpadEntryType.Tab","entryName":"Home","entryImage":"css/img/missing_screen.png"}],[],[],[],[],[],[]],"roots":[{"__Ref":0,"rule":1,"object":0}]}

@kulshekhar I think the entry is added after the first run through the code.
Use indexedDB.deleteDatabase("speedpadDB") to clear the database and start fresh.

@floitschG thanks, that was helpful.

@bjesuiter I'm now getting the following log when I run the app (I've placed the _log calls as per your post on SO:

2016.49.03 17:49:04.206 speedpad.storage_service    [FINEST]:   initDbs called
js_primitives.dart:31 2016.49.03 17:49:04.418   speedpad.storage_service    [FINEST]:   getLinkStructure called
js_primitives.dart:31 2016.49.03 17:49:04.427   speedpad.storage_service    [FINEST]:   No Structure saved in database - create default structure
js_primitives.dart:31 2016.49.03 17:49:04.442   SharedClassesLib.serialization.helper   [FINE]: Serialize JSArray
js_primitives.dart:31 2016.49.03 17:49:04.494   speedpad.storage_service    [FINEST]:   dbKey: structure
js_primitives.dart:31 2016.49.03 17:49:04.505   speedpad.cache_service  [SEVERE]:   Error with storage initialization: Invalid argument: null

To test this, I do the following:

  1. Remove the indexedDb database (indexedDB.deleteDatabase("speedpadDB")
  2. Reload the tab in chrome

Please let me know if there's something I'm doing wrong. If I'm doing this right then it looks like the result I'm seeing is in line with your expectations

Hm, no, seems fine what you're doing. I didn't get dbKey structure yesterday, besides getting the "create default structure" message. Now getLinkStructure seems to work. But I did not find the Invalid argument error yet.

EDIT:
I found the null error. It was in
requestLinksInTab function, the next function after the structure is initialized.
There i had:

String stringData = await _tabDb.getByKey(tabId);
List<LinkEntry> links = deserialize(stringData) ?? [];

The problem occurred when stringData was empty, because deserialize threw. Now i changed it to:

List<LinkEntry> links = (stringData != null) ? deserialize(stringData) : [];

And it works.

Okay, besides the null error: I don't know, where this weird behaviour of await came from in the first place. Because at first the program did not execute this far, as stated in the SO article.

I will watch out for something like this. If such things come across again, i will reopen this thread.
Thanks for being patient and helping me out! :)

Great you found the problem. I had already debugged it up to the point where the call to requestLinksInTab was throwing (but hadn't stepped through it yet), but hadn't yet made it to that line.

Yes, please: if you see a problem with await, file a bug. (I would just open a new one, unless it is in the same code section.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DartBot picture DartBot  路  3Comments

ranquild picture ranquild  路  3Comments

jmesserly picture jmesserly  路  3Comments

gspencergoog picture gspencergoog  路  3Comments

DartBot picture DartBot  路  3Comments