{"ast":null,"code":"import { Subject } from '../Subject';\nimport { asyncScheduler } from '../scheduler/async';\nimport { Subscription } from '../Subscription';\nimport { operate } from '../util/lift';\nimport { createOperatorSubscriber } from './OperatorSubscriber';\nimport { arrRemove } from '../util/arrRemove';\nimport { popScheduler } from '../util/args';\nimport { executeSchedule } from '../util/executeSchedule';\nexport function windowTime(windowTimeSpan) {\n  var _a, _b;\n  for (var _len = arguments.length, otherArgs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n    otherArgs[_key - 1] = arguments[_key];\n  }\n  var scheduler = (_a = popScheduler(otherArgs)) !== null && _a !== void 0 ? _a : asyncScheduler;\n  var windowCreationInterval = (_b = otherArgs[0]) !== null && _b !== void 0 ? _b : null;\n  var maxWindowSize = otherArgs[1] || Infinity;\n  return operate(function (source, subscriber) {\n    var windowRecords = [];\n    var restartOnClose = false;\n    var closeWindow = function closeWindow(record) {\n      var window = record.window,\n        subs = record.subs;\n      window.complete();\n      subs.unsubscribe();\n      arrRemove(windowRecords, record);\n      restartOnClose && startWindow();\n    };\n    var startWindow = function startWindow() {\n      if (windowRecords) {\n        var subs = new Subscription();\n        subscriber.add(subs);\n        var window = new Subject();\n        var record = {\n          window: window,\n          subs: subs,\n          seen: 0\n        };\n        windowRecords.push(record);\n        subscriber.next(window.asObservable());\n        executeSchedule(subs, scheduler, function () {\n          return closeWindow(record);\n        }, windowTimeSpan);\n      }\n    };\n    if (windowCreationInterval !== null && windowCreationInterval >= 0) {\n      executeSchedule(subscriber, scheduler, startWindow, windowCreationInterval, true);\n    } else {\n      restartOnClose = true;\n    }\n    startWindow();\n    var loop = function loop(cb) {\n      return windowRecords.slice().forEach(cb);\n    };\n    var terminate = function terminate(cb) {\n      loop(function (_ref) {\n        var window = _ref.window;\n        return cb(window);\n      });\n      cb(subscriber);\n      subscriber.unsubscribe();\n    };\n    source.subscribe(createOperatorSubscriber(subscriber, function (value) {\n      loop(function (record) {\n        record.window.next(value);\n        maxWindowSize <= ++record.seen && closeWindow(record);\n      });\n    }, function () {\n      return terminate(function (consumer) {\n        return consumer.complete();\n      });\n    }, function (err) {\n      return terminate(function (consumer) {\n        return consumer.error(err);\n      });\n    }));\n    return function () {\n      windowRecords = null;\n    };\n  });\n}\n//# sourceMappingURL=windowTime.js.map","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}