/**
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
import"./boot.js";import"./mixin.js";import"./async.js";export class Debouncer{constructor(){this._asyncModule=null,this._callback=null,this._timer=null}setConfig(e,s){this._asyncModule=e,this._callback=s,this._timer=this._asyncModule.run((()=>{this._timer=null,t.delete(this),this._callback()}))}cancel(){this.isActive()&&(this._cancelAsync(),t.delete(this))}_cancelAsync(){this.isActive()&&(this._asyncModule.cancel(this._timer),this._timer=null)}flush(){this.isActive()&&(this.cancel(),this._callback())}isActive(){return null!=this._timer}static debounce(t,e,s){return t instanceof Debouncer?t._cancelAsync():t=new Debouncer,t.setConfig(e,s),t}}let t=new Set;export const enqueueDebouncer=function(e){t.add(e)};export const flushDebouncers=function(){const e=Boolean(t.size);return t.forEach((t=>{try{t.flush()}catch(t){setTimeout((()=>{throw t}))}})),e};