toggleLoading: fix race (#27905)
toggleLoading: fix race (#27905)

* toggleLoading: fix race

* add a test

* add second test

* lint🤕

* timer should be called
rsimha-amp/amphtml,mhc-gh/amphtml,lannka/amphtml,alanorozco/amphtml,prateekbh/amphtml,smartadserver/amphtml,jridgewell/amphtml,prateekbh/amphtml,danielrozenberg/amphtml,yandex-pcode/amphtml,danielrozenberg/amphtml,Gregable/amphtml,lannka/amphtml,media-net/amphtml,prateekbh/amphtml,danielrozenberg/amphtml,voyagegroup/amphtml,yandex-pcode/amphtml,jpettitt/amphtml,jmadler/amphtml,yandex-pcode/amphtml,jridgewell/amphtml,zhouyx/amphtml,adup-tech/amphtml,alanorozco/amphtml,media-net/amphtml,jpettitt/amphtml,mhc-gh/amphtml,media-net/amphtml,lannka/amphtml,danielrozenberg/amphtml,smartadserver/amphtml,danielrozenberg/amphtml,smartadserver/amphtml,rsimha-amp/amphtml,media-net/amphtml,zhouyx/amphtml,jpettitt/amphtml,adup-tech/amphtml,ampproject/amphtml,jpettitt/amphtml,ampproject/amphtml,Gregable/amphtml,Gregable/amphtml,alanorozco/amphtml,yandex-pcode/amphtml,rsimha-amp/amphtml,sharethrough/amphtml,alanorozco/amphtml,voyagegroup/amphtml,lannka/amphtml,smartadserver/amphtml,mhc-gh/amphtml,prateekbh/amphtml,nexxtv/amphtml,nexxtv/amphtml,danielrozenberg/amphtml,adup-tech/amphtml,ampproject/amphtml,smartadserver/amphtml,jridgewell/amphtml,alanorozco/amphtml,sharethrough/amphtml,mhc-gh/amphtml,jpettitt/amphtml,nexxtv/amphtml,honeybadgerdontcare/amphtml,voyagegroup/amphtml,lannka/amphtml,honeybadgerdontcare/amphtml,smartadserver/amphtml,nexxtv/amphtml,lannka/amphtml,jridgewell/amphtml,adup-tech/amphtml,honeybadgerdontcare/amphtml,ampproject/amphtml,mhc-gh/amphtml,prateekbh/amphtml,jmadler/amphtml,ampproject/amphtml,jridgewell/amphtml,rsimha-amp/amphtml,danielrozenberg/amphtml,rsimha-amp/amphtml,adup-tech/amphtml,media-net/amphtml,jmadler/amphtml,Gregable/amphtml,zhouyx/amphtml,honeybadgerdontcare/amphtml,voyagegroup/amphtml,yandex-pcode/amphtml,lannka/amphtml,prateekbh/amphtml,ampproject/amphtml,sharethrough/amphtml,Gregable/amphtml,alanorozco/amphtml,jmadler/amphtml,voyagegroup/amphtml,alanorozco/amphtml,jmadler/amphtml,zhouyx/amphtml,jridgewell/amphtml,Gregable/amphtml,prateekbh/amphtml,jpettitt/amphtml,zhouyx/amphtml,jmadler/amphtml,ampproject/amphtml,Gregable/amphtml,nexxtv/amphtml,media-net/amphtml,jridgewell/amphtml,voyagegroup/amphtml,alanorozco/amphtml,nexxtv/amphtml,yandex-pcode/amphtml,jpettitt/amphtml,media-net/amphtml,honeybadgerdontcare/amphtml,sharethrough/amphtml,Gregable/amphtml,ampproject/amphtml,voyagegroup/amphtml,zhouyx/amphtml,rsimha-amp/amphtml,adup-tech/amphtml,sharethrough/amphtml,mhc-gh/amphtml,zhouyx/amphtml,mhc-gh/amphtml,nexxtv/amphtml,mhc-gh/amphtml,media-net/amphtml,yandex-pcode/amphtml,honeybadgerdontcare/amphtml,sharethrough/amphtml,rsimha-amp/amphtml,jpettitt/amphtml,danielrozenberg/amphtml,honeybadgerdontcare/amphtml