i trying to create synchronized queue of api requests with AngularJS.
class x {
    public y() {
        ...
        restRequest();
    }
}
i have this class, and i have some white board canvas. when i drop some entity on the canvas, the method y calling.
so for example, i dragged and dropped 5 entities quickly. its created for me 5 api requests.
i want to add the restRequest to some sync queue that when i will dropped 5 entites it will be queue of 5 request and request 1 will start, when it will finish the next request will start, etc... (synchronize queue).
i tried with this code:
class x {
    private queue: object = {};
    
    public y() {
        const uniqueId: number = Date.now();
        
        let queueIsEmpty = _.isEmpty(this.queue);
        
        const func = setInterval(() => {
            if(queueIsEmpty) {
                this.queue[uniqueId] = true;
                clearInterval(func);
                restRequest();
            }
            queueIsEmpty = _.isEmpty(this.queue);
        }, 1000);
    }
    
    private restRequest() {
        
    }
}
but this code is wrong because there is race, if i drag & drop 5 entities there is situation that after the first one finish its enter to the block 4 times together.
So, how can i create sync queue of api request? tnx a lot
 
    