|
@@ -323,6 +323,44 @@ function Observable:average()
|
|
end)
|
|
end)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+--- Returns an Observable that buffers values from the original and produces them as multiple
|
|
|
|
+-- values.
|
|
|
|
+-- @arg {number} size - The size of the buffer.
|
|
|
|
+function Observable:buffer(size)
|
|
|
|
+ return Observable.create(function(observer)
|
|
|
|
+ local buffer = {}
|
|
|
|
+
|
|
|
|
+ local function emit()
|
|
|
|
+ if #buffer > 0 then
|
|
|
|
+ observer:onNext(util.unpack(buffer))
|
|
|
|
+ buffer = {}
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ local function onNext(...)
|
|
|
|
+ local values = {...}
|
|
|
|
+ for i = 1, #values do
|
|
|
|
+ table.insert(buffer, values[i])
|
|
|
|
+ if #buffer >= size then
|
|
|
|
+ emit()
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ local function onError(message)
|
|
|
|
+ emit()
|
|
|
|
+ return observer:onError(message)
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ local function onCompleted()
|
|
|
|
+ emit()
|
|
|
|
+ return observer:onCompleted()
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ return self:subscribe(onNext, onError, onCompleted)
|
|
|
|
+ end)
|
|
|
|
+end
|
|
|
|
+
|
|
--- Returns a new Observable that runs a combinator function on the most recent values from a set
|
|
--- Returns a new Observable that runs a combinator function on the most recent values from a set
|
|
-- of Observables whenever any of them produce a new value. The results of the combinator function
|
|
-- of Observables whenever any of them produce a new value. The results of the combinator function
|
|
-- are produced by the new Observable.
|
|
-- are produced by the new Observable.
|
|
@@ -1089,44 +1127,6 @@ function Observable:with(...)
|
|
end)
|
|
end)
|
|
end
|
|
end
|
|
|
|
|
|
---- Returns an Observable that buffers values from the original and produces them as multiple
|
|
|
|
--- values.
|
|
|
|
--- @arg {number} size - The size of the buffer.
|
|
|
|
-function Observable:wrap(size)
|
|
|
|
- return Observable.create(function(observer)
|
|
|
|
- local buffer = {}
|
|
|
|
-
|
|
|
|
- local function emit()
|
|
|
|
- if #buffer > 0 then
|
|
|
|
- observer:onNext(util.unpack(buffer))
|
|
|
|
- buffer = {}
|
|
|
|
- end
|
|
|
|
- end
|
|
|
|
-
|
|
|
|
- local function onNext(...)
|
|
|
|
- local values = {...}
|
|
|
|
- for i = 1, #values do
|
|
|
|
- table.insert(buffer, values[i])
|
|
|
|
- if #buffer >= size then
|
|
|
|
- emit()
|
|
|
|
- end
|
|
|
|
- end
|
|
|
|
- end
|
|
|
|
-
|
|
|
|
- local function onError(message)
|
|
|
|
- emit()
|
|
|
|
- return observer:onError(message)
|
|
|
|
- end
|
|
|
|
-
|
|
|
|
- local function onCompleted()
|
|
|
|
- emit()
|
|
|
|
- return observer:onCompleted()
|
|
|
|
- end
|
|
|
|
-
|
|
|
|
- return self:subscribe(onNext, onError, onCompleted)
|
|
|
|
- end)
|
|
|
|
-end
|
|
|
|
-
|
|
|
|
--- @class ImmediateScheduler
|
|
--- @class ImmediateScheduler
|
|
-- @description Schedules Observables by running all operations immediately.
|
|
-- @description Schedules Observables by running all operations immediately.
|
|
local ImmediateScheduler = {}
|
|
local ImmediateScheduler = {}
|
|
@@ -1352,6 +1352,8 @@ function BehaviorSubject:getValue()
|
|
return self.value and util.unpack(self.value)
|
|
return self.value and util.unpack(self.value)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+Observable.wrap = Observable.buffer
|
|
|
|
+
|
|
return {
|
|
return {
|
|
util = util,
|
|
util = util,
|
|
Subscription = Subscription,
|
|
Subscription = Subscription,
|