Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
pygolang
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
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
pygolang
Commits
4f6a9e09
Commit
4f6a9e09
authored
Oct 04, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
time: Add type annotations to function arguments where possible
parent
106c1b95
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
golang/_time.pyx
golang/_time.pyx
+10
-10
No files found.
golang/_time.pyx
View file @
4f6a9e09
...
...
@@ -44,7 +44,7 @@ def pysleep(double dt):
#
# Note: there is no way to stop created ticker.
# Note: for dt <= 0, contrary to Ticker, tick returns nilchan instead of panicking.
def
tick
(
d
t
):
# -> chan time
def
tick
(
d
ouble
dt
):
# -> chan time
if
dt
<=
0
:
return
pynilchan
return
Ticker
(
dt
).
c
...
...
@@ -52,14 +52,14 @@ def tick(dt): # -> chan time
# after returns channel connected to dt timer.
#
# Note: with after there is no way to stop/garbage-collect created timer until it fires.
def
after
(
d
t
):
# -> chan time
def
after
(
d
ouble
dt
):
# -> chan time
return
Timer
(
dt
).
c
# after_func arranges to call f after dt time.
#
# The function will be called in its own goroutine.
# Returned timer can be used to cancel the call.
def
after_func
(
dt
,
f
):
# -> Timer
def
after_func
(
d
ouble
d
t
,
f
):
# -> Timer
return
Timer
(
dt
,
f
=
f
)
...
...
@@ -75,7 +75,7 @@ cdef class Ticker:
cdef
sync
.
Mutex
_mu
cdef
bint
_stop
def
__init__
(
self
,
dt
):
def
__init__
(
Ticker
self
,
double
dt
):
if
dt
<=
0
:
pypanic
(
"ticker: dt <= 0"
)
self
.
c
=
pychan
(
1
)
# 1-buffer -- same as in Go
...
...
@@ -86,7 +86,7 @@ cdef class Ticker:
# stop cancels the ticker.
#
# It is guaranteed that ticker channel is empty after stop completes.
def
stop
(
self
):
def
stop
(
Ticker
self
):
self
.
_mu
.
lock
()
self
.
_stop
=
True
...
...
@@ -95,7 +95,7 @@ cdef class Ticker:
self
.
c
.
recv
()
self
.
_mu
.
unlock
()
def
_tick
(
self
):
def
_tick
(
Ticker
self
):
while
1
:
# XXX adjust for accumulated error δ?
pysleep
(
self
.
_dt
)
...
...
@@ -129,7 +129,7 @@ cdef class Timer:
cdef
double
_dt
# +inf - stopped, otherwise - armed
cdef
int
_ver
# current timer was armed by n'th reset
def
__init__
(
self
,
dt
,
f
=
None
):
def
__init__
(
Timer
self
,
double
dt
,
f
=
None
):
self
.
_f
=
f
self
.
c
=
pychan
(
1
)
if
f
is
None
else
pynilchan
self
.
_dt
=
INFINITY
...
...
@@ -149,7 +149,7 @@ cdef class Timer:
# Note: similarly to Go, if Timer is used with function - it is not
# guaranteed that after stop the function is not running - in such case
# the caller must explicitly synchronize with that function to complete.
def
stop
(
self
):
# -> canceled
def
stop
(
Timer
self
):
# -> canceled
self
.
_mu
.
lock
()
if
self
.
_dt
==
INFINITY
:
...
...
@@ -169,7 +169,7 @@ cdef class Timer:
# reset rearms the timer.
#
# the timer must be either already stopped or expired.
def
reset
(
self
,
dt
):
def
reset
(
Timer
self
,
double
dt
):
self
.
_mu
.
lock
()
if
self
.
_dt
!=
INFINITY
:
self
.
_mu
.
unlock
()
...
...
@@ -180,7 +180,7 @@ cdef class Timer:
self
.
_mu
.
unlock
()
def
_fire
(
self
,
dt
,
ver
):
def
_fire
(
Timer
self
,
double
dt
,
int
ver
):
pysleep
(
dt
)
self
.
_mu
.
lock
()
if
self
.
_ver
!=
ver
:
...
...
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