SpeechAPIの非同期イベントを並べなおすときに、複数のイベントを順に呼ぶ必要があったので作った。
コンストラクタで空のPromiseを呼んでその結果をnextに保存しておく。
作った後で気が付いたけど、これクラスにする必要ないね。
class PromiseStack { constructor(){ this.next=new Promise(function(callback){return callback();}).then(function(){}); } put(f) { const _t=this; this.next=this.next.then(f); } } const pr=new PromiseStack(); pr.put(function(){console.log(0);}); pr.put(function(){console.log(1);}); pr.put(function(){console.log(2);}); pr.put(function(){console.log(3);}); pr.put(function(){console.log(4);pr.put(function(){console.log(5)})});