Reputation: 92587
this question is a little related with this one. Here we have following code in ANGULAR:
private async createFloor(name)
{
let newFloorData = {
floorName: name,
percent: 0,
requestSubscription: null,
finish: false,
deleted: false,
};
...
return newFloorData;
}
public async addFloor(event)
{
let newFloorData = this.createFloor('test name');
debugger;
...
}
And in debugger chrome debugger when i look on newFloorData
I get following information:
ZoneAwarePromise
__zone_symbol__state : true
__zone_symbol__value : {percent: 0, requestSubscription: null, finish: false, deleted: false}
proto : Object
However if I add await
in addFloor
function:
public async addFloor(event)
{
let newFloorData = await this.createFloor('test name');
debugger;
...
}
In debugger I just get newFloorData object returned by createFloor
(which is intuitive).
Question: Why? What mechanism is behind this behaviour?
Upvotes: 1
Views: 353
Reputation: 657851
Angular uses zone.js to patch almost all async APIs. It does this to get notified when an async action happened and then triggers a change detection run.
See also
Upvotes: 2