Skip to content

Instantly share code, notes, and snippets.

@joelnet
Last active March 8, 2024 10:04
Show Gist options
  • Select an option

  • Save joelnet/b286721a933e7e410120a8a2866dbcc8 to your computer and use it in GitHub Desktop.

Select an option

Save joelnet/b286721a933e7e410120a8a2866dbcc8 to your computer and use it in GitHub Desktop.

Revisions

  1. joelnet revised this gist Aug 17, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions promiseSerial.js
    Original file line number Diff line number Diff line change
    @@ -21,5 +21,5 @@ const funcs = urls.map(url => () => $.ajax(url))

    // execute Promises in serial
    promiseSerial(funcs)
    .then(console.log)
    .catch(console.error)
    .then(console.log.bind(console))
    .catch(console.error.bind(console))
  2. joelnet revised this gist Jan 5, 2017. 2 changed files with 13 additions and 14 deletions.
    15 changes: 13 additions & 2 deletions promiseSerial.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,18 @@
    * .then(console.log)
    * .catch(console.error)
    */
    export const promiseSerial = funcs =>
    const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))),
    Promise.resolve([]))
    Promise.resolve([]))

    // some url's to resolve
    const urls = ['/url1', '/url2', '/url3']

    // convert each url to a function that returns a promise
    const funcs = urls.map(url => () => $.ajax(url))

    // execute Promises in serial
    promiseSerial(funcs)
    .then(console.log)
    .catch(console.error)
    12 changes: 0 additions & 12 deletions zdemo.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +0,0 @@
    import { promiseSerial} from './promiseSerial'

    // some url's to resolve
    const urls = ['/url1', '/url2', '/url3']

    // convert each url to a function that returns a promise
    const funcs = urls.map(url => () => $.ajax(url))

    // execute Promises in serial
    promiseSerial(funcs)
    .then(console.log)
    .catch(console.error)
  3. joelnet renamed this gist Jan 4, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. joelnet revised this gist Jan 4, 2017. 2 changed files with 15 additions and 14 deletions.
    15 changes: 1 addition & 14 deletions demo.js
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,4 @@
    /*
    * promiseSerial resolves Promises sequentially.
    * @example
    * const urls = ['/url1', '/url2', '/url3']
    * const funcs = urls.map(url => () => $.ajax(url))
    *
    * promiseSerial(funcs)
    * .then(console.log)
    * .catch(console.error)
    */
    const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))),
    Promise.resolve([]))
    import { promiseSerial} from './promiseSerial'

    // some url's to resolve
    const urls = ['/url1', '/url2', '/url3']
    14 changes: 14 additions & 0 deletions promiseSerial.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    /*
    * promiseSerial resolves Promises sequentially.
    * @example
    * const urls = ['/url1', '/url2', '/url3']
    * const funcs = urls.map(url => () => $.ajax(url))
    *
    * promiseSerial(funcs)
    * .then(console.log)
    * .catch(console.error)
    */
    export const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))),
    Promise.resolve([]))
  5. joelnet revised this gist Jan 4, 2017. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion demo.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,13 @@
    // execute promises in serial.
    /*
    * promiseSerial resolves Promises sequentially.
    * @example
    * const urls = ['/url1', '/url2', '/url3']
    * const funcs = urls.map(url => () => $.ajax(url))
    *
    * promiseSerial(funcs)
    * .then(console.log)
    * .catch(console.error)
    */
    const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))),
  6. joelnet revised this gist Jan 4, 2017. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions promiseSerial.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +0,0 @@
    // execute promises in serial.
    const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))),
    Promise.resolve([]))
  7. joelnet revised this gist Jan 4, 2017. 2 changed files with 17 additions and 12 deletions.
    16 changes: 16 additions & 0 deletions demo.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    // execute promises in serial.
    const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))),
    Promise.resolve([]))

    // some url's to resolve
    const urls = ['/url1', '/url2', '/url3']

    // convert each url to a function that returns a promise
    const funcs = urls.map(url => () => $.ajax(url))

    // execute Promises in serial
    promiseSerial(funcs)
    .then(console.log)
    .catch(console.error)
    13 changes: 1 addition & 12 deletions promiseSerial.js
    Original file line number Diff line number Diff line change
    @@ -2,15 +2,4 @@
    const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))),
    Promise.resolve([]))

    // some url's to resolve
    const urls = ['/url1', '/url2', '/url3']

    // convert each url to a function that returns a promise
    const funcs = urls.map(url => () => $.ajax(url))

    // execute Promises in serial
    promiseSerial(funcs)
    .then(console.log)
    .catch(console.error)
    Promise.resolve([]))
  8. joelnet revised this gist Jan 4, 2017. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions promiseSerial.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    // some url's to resolve
    const urls = ['/url1', '/url2', '/url3']

    // convert each url to a function that returns a promise
    const funcs = urls.map(url => () => $.ajax(url))

    // execute promises in serial.
    const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))),
    Promise.resolve([]))

    // some url's to resolve
    const urls = ['/url1', '/url2', '/url3']

    // convert each url to a function that returns a promise
    const funcs = urls.map(url => () => $.ajax(url))

    // execute Promises in serial
    promiseSerial(funcs)
    .then(console.log)
  9. joelnet revised this gist Jan 4, 2017. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions promiseSerial.js
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,7 @@ const urls = ['/url1', '/url2', '/url3']
    // convert each url to a function that returns a promise
    const funcs = urls.map(url => () => $.ajax(url))

    /*
    * Execute promises in serial.
    */
    // execute promises in serial.
    const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))),
  10. joelnet revised this gist Jan 4, 2017. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion promiseSerial.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,18 @@
    // some url's to resolve
    const urls = ['/url1', '/url2', '/url3']

    // convert each url to a function that returns a promise
    const funcs = urls.map(url => () => $.ajax(url))

    /*
    * Execute promises in serial.
    */
    const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))),
    Promise.resolve([]))
    Promise.resolve([]))

    // execute Promises in serial
    promiseSerial(funcs)
    .then(console.log)
    .catch(console.error)
  11. joelnet revised this gist Jan 4, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion promiseSerial.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))), Promise.resolve([]))
    promise.then(result => func().then(Array.prototype.concat.bind(result))),
    Promise.resolve([]))
  12. joelnet created this gist Jan 4, 2017.
    3 changes: 3 additions & 0 deletions promiseSerial.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    const promiseSerial = funcs =>
    funcs.reduce((promise, func) =>
    promise.then(result => func().then(Array.prototype.concat.bind(result))), Promise.resolve([]))