Make the flush() compatible with async/await

Change-Id: I87b9ade6abb115ab9508322d4f2442cb62b3e7f1
This commit is contained in:
Dmitrii Filippov
2020-05-08 16:26:10 +02:00
parent 861628fdab
commit 66b6088d03

View File

@@ -22,7 +22,8 @@ self.assert = window.chai.assert;
/**
* Triggers a flush of any pending events, observations, etc and calls you back
* after they have been processed.
* after they have been processed if callback is passed; otherwise returns
* promise.
*
* @param {function()} callback
*/
@@ -31,7 +32,13 @@ function flush(callback) {
// doesn't support a callback yet
// (https://github.com/Polymer/polymer-dev/issues/851)
window.Polymer.dom.flush();
window.setTimeout(callback, 0);
if (callback) {
window.setTimeout(callback, 0);
} else {
return new Promise(resolve => {
window.setTimeout(resolve, 0);
});
}
}
self.flush = flush;