"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/decompress-zip/node_modules/q/queue.js" (8 Mar 2017, 941 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2 var Q = require("./q");
    3 
    4 module.exports = Queue;
    5 function Queue() {
    6     var ends = Q.defer();
    7     var closed = Q.defer();
    8     return {
    9         put: function (value) {
   10             var next = Q.defer();
   11             ends.resolve({
   12                 head: value,
   13                 tail: next.promise
   14             });
   15             ends.resolve = next.resolve;
   16         },
   17         get: function () {
   18             var result = ends.promise.get("head");
   19             ends.promise = ends.promise.get("tail");
   20             return result.fail(function (error) {
   21                 closed.resolve(error);
   22                 throw error;
   23             });
   24         },
   25         closed: closed.promise,
   26         close: function (error) {
   27             error = error || new Error("Can't get value from closed queue");
   28             var end = {head: Q.reject(error)};
   29             end.tail = end;
   30             ends.resolve(end);
   31             return closed.promise;
   32         }
   33     };
   34 }
   35