/** @license MIT License (c) copyright 2010-2016 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */

/**
 * Doubly linked list
 * @constructor
 */
export default class LinkedList {
  constructor () {
    this.head = null
    this.length = 0
  }

  /**
   * Add a node to the end of the list
   * @param {{prev:Object|null, next:Object|null, dispose:function}} x node to add
   */
  add (x) {
    if (this.head !== null) {
      this.head.prev = x
      x.next = this.head
    }
    this.head = x
    ++this.length
  }

  /**
   * Remove the provided node from the list
   * @param {{prev:Object|null, next:Object|null, dispose:function}} x node to remove
   */
  remove (x) { // eslint-disable-line  complexity
    --this.length
    if (x === this.head) {
      this.head = this.head.next
    }
    if (x.next !== null) {
      x.next.prev = x.prev
      x.next = null
    }
    if (x.prev !== null) {
      x.prev.next = x.next
      x.prev = null
    }
  }

  /**
   * @returns {boolean} true iff there are no nodes in the list
   */
  isEmpty () {
    return this.length === 0
  }

  /**
   * Dispose all nodes
   * @returns {Promise} promise that fulfills when all nodes have been disposed,
   *  or rejects if an error occurs while disposing
   */
  dispose () {
    if (this.isEmpty()) {
      return Promise.resolve()
    }

    const promises = []
    let x = this.head
    this.head = null
    this.length = 0

    while (x !== null) {
      promises.push(x.dispose())
      x = x.next
    }

    return Promise.all(promises)
  }
}

@@ -40,13 +40,8 @@
 2010
--2016
  ori
@@ -70,63 +70,8 @@
 s */
-%0A/** @author Brian Cavalier */%0A/** @author John Hann */
 %0A%0A/*
@@ -1100,125 +1100,13 @@
 ns %7B
-Promise%7D promise that fulfills when all nodes have been disposed,%0A   *  or rejects if an error occurs while disposing
+void%7D
 %0A   
@@ -1165,67 +1165,28 @@
 turn
- Promise.resolve()%0A    %7D%0A%0A    const promises = %5B%5D%0A    let x
+%0A    %7D%0A%0A    let head
  = t
@@ -1247,17 +1247,20 @@
  while (
-x
+head
  !== nul
@@ -1274,23 +1274,12 @@
     
-promises.push(x
+head
 .dis
@@ -1288,66 +1288,37 @@
 se()
-)
 %0A      
-x = x.next%0A    %7D%0A%0A    return Promise.all(promises)
+head = head.next%0A    %7D
 %0A  %7D

Remove leftover promise usage in mergeConcurrently list (#169)