A job queue in two lines of JS

If you need a job queue in JS, you can do it in two lines: type Job = ( ) => Promise < unknown > ; let chain = Promise . resolve ( ) ; const enqueue = ( job : Job ) => chain = chain . then ( job , job ) ; For example, if your app makes API requests, you may need requests to be processed in the order they were dispatched: function setDone ( id : string , done : boolean ) { enqueue ( ( ) => fetch (…