mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
positive limit support
This commit is contained in:
@@ -574,10 +574,20 @@ function mongo_cursor:hasNext()
|
|||||||
|
|
||||||
if ok then
|
if ok then
|
||||||
if doc then
|
if doc then
|
||||||
self.__document = result.result
|
local doc = result.result
|
||||||
|
self.__document = doc
|
||||||
self.__data = result.data
|
self.__data = result.data
|
||||||
self.__ptr = 1
|
self.__ptr = 1
|
||||||
self.__cursor = cursor
|
self.__cursor = cursor
|
||||||
|
local limit = self.__limit
|
||||||
|
if cursor and limit > 0 then
|
||||||
|
limit = limit - #doc
|
||||||
|
if limit <= 0 then
|
||||||
|
-- reach limit
|
||||||
|
self:close()
|
||||||
|
end
|
||||||
|
self.__limit = limit
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
self.__document = nil
|
self.__document = nil
|
||||||
@@ -615,11 +625,11 @@ function mongo_cursor:next()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function mongo_cursor:close()
|
function mongo_cursor:close()
|
||||||
-- todo: warning hasNext after close
|
|
||||||
if self.__cursor then
|
if self.__cursor then
|
||||||
local sock = self.__collection.connection.__sock
|
local sock = self.__collection.connection.__sock
|
||||||
local pack = driver.kill(self.__cursor)
|
local pack = driver.kill(self.__cursor)
|
||||||
sock:request(pack)
|
sock:request(pack)
|
||||||
|
self.__cursor = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user