Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

queue.js 500B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var Queue = function () {
  3. this.head = null;
  4. this.tail = null;
  5. };
  6. Queue.prototype = {
  7. add: function (item) {
  8. var entry = { item: item, next: null };
  9. var tail = this.tail;
  10. if (tail) tail.next = entry;
  11. else this.head = entry;
  12. this.tail = entry;
  13. },
  14. get: function () {
  15. var entry = this.head;
  16. if (entry) {
  17. var next = this.head = entry.next;
  18. if (next === null) this.tail = null;
  19. return entry.item;
  20. }
  21. }
  22. };
  23. module.exports = Queue;