Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZEO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZEO
Commits
f96776b3
Commit
f96776b3
authored
Jul 16, 2016
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed load_before and preftech to use generators rather than callbacks
parent
db9d3da5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
21 deletions
+51
-21
src/ZEO/asyncio/client.py
src/ZEO/asyncio/client.py
+51
-21
No files found.
src/ZEO/asyncio/client.py
View file @
f96776b3
...
...
@@ -8,6 +8,7 @@ else:
from
ZEO.Exceptions
import
ClientDisconnected
from
ZODB.ConflictResolution
import
ResolvedSerial
import
concurrent.futures
import
functools
import
logging
import
random
import
threading
...
...
@@ -27,6 +28,37 @@ Fallback = object()
local_random
=
random
.
Random
()
# use separate generator to facilitate tests
def
future_generator
(
func
):
"""Decorates a generator that generates futures
"""
@
functools
.
wraps
(
func
)
def
call_generator
(
*
args
,
**
kw
):
gen
=
func
(
*
args
,
**
kw
)
try
:
f
=
next
(
gen
)
except
StopIteration
:
gen
.
close
()
else
:
def
store
(
gen
,
future
):
@
future
.
add_done_callback
def
_
(
future
):
try
:
try
:
result
=
future
.
result
()
except
Exception
as
exc
:
f
=
gen
.
throw
(
exc
)
else
:
f
=
gen
.
send
(
result
)
except
StopIteration
:
gen
.
close
()
else
:
store
(
gen
,
f
)
store
(
gen
,
f
)
return
call_generator
class
Protocol
(
base
.
Protocol
):
"""asyncio low-level ZEO client interface
"""
...
...
@@ -249,7 +281,7 @@ class Protocol(base.Protocol):
self
.
futures
[
message_id
]
=
future
self
.
_write
(
self
.
encode
(
message_id
,
False
,
'loadBefore'
,
(
oid
,
tid
)))
return
future
.
add_done_callback
return
future
# Methods called by the server.
# WARNING WARNING we can't call methods that call back to us
...
...
@@ -525,30 +557,28 @@ class Client(object):
# Special methods because they update the cache.
@
future_generator
def
load_before_threadsafe
(
self
,
future
,
oid
,
tid
):
data
=
self
.
cache
.
loadBefore
(
oid
,
tid
)
if
data
is
not
None
:
future
.
set_result
(
data
)
elif
self
.
ready
:
@
self
.
protocol
.
load_before
(
oid
,
tid
)
def
load_before
(
load_future
):
try
:
data
=
load_future
.
result
()
data
=
yield
self
.
protocol
.
load_before
(
oid
,
tid
)
except
Exception
as
exc
:
future
.
set_exception
(
exc
)
else
:
future
.
set_result
(
data
)
if
data
:
data
,
start
,
end
=
data
self
.
cache
.
store
(
oid
,
start
,
end
,
data
)
except
Exception
as
exc
:
future
.
set_exception
(
exc
)
else
:
self
.
_when_ready
(
self
.
load_before_threadsafe
,
future
,
oid
,
tid
)
@
future_generator
def
_prefetch
(
self
,
oid
,
tid
):
@
self
.
protocol
.
load_before
(
oid
,
tid
)
def
load_before
(
load_future
):
try
:
data
=
load_future
.
result
(
)
data
=
yield
self
.
protocol
.
load_before
(
oid
,
tid
)
if
data
:
data
,
start
,
end
=
data
self
.
cache
.
store
(
oid
,
start
,
end
,
data
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment