Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Nathan Graule
call
Commits
64410d55
Commit
64410d55
authored
Aug 07, 2018
by
Nathan Graule
💻
Browse files
Transfer type hints to comments for Python 2.7 compatible code
parent
fc60df43
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
+18
-8
call/__init__.py
call/__init__.py
+18
-8
No files found.
call/__init__.py
View file @
64410d55
...
...
@@ -18,13 +18,16 @@ class Call:
RESOLVED
=
'RESOLVED'
REJECTED
=
'REJECTED'
def
__init__
(
self
,
callback
:
Callback
):
def
__init__
(
self
,
callback
):
# type: (Callback) -> Call
self
.
status
=
self
.
PENDING
self
.
chain
=
[]
self
.
data
=
None
# type: T
self
.
error
=
None
# type: E
self
.
t
=
Thread
(
target
=
callback
,
args
=
(
self
.
_on_resolve
,
self
.
_on_rejected
))
self
.
t
.
start
()
def
then
(
self
,
callback
:
Thenable
):
def
then
(
self
,
callback
):
# type: (Thenable) -> Call
def
cb
(
resolve
:
Callable
,
reject
:
Callable
):
self
.
t
.
join
()
if
self
.
status
==
self
.
REJECTED
:
...
...
@@ -38,7 +41,8 @@ class Call:
return
Call
(
cb
)
def
catch
(
self
,
callback
:
Thenable
):
def
catch
(
self
,
callback
):
# type: (Thenable) -> Call
def
cb
(
resolve
,
reject
):
self
.
t
.
join
()
if
self
.
status
==
self
.
REJECTED
:
...
...
@@ -51,6 +55,7 @@ class Call:
return
Call
(
cb
)
def
wait
(
self
):
# type: () -> T
self
.
t
.
join
()
if
self
.
status
==
self
.
RESOLVED
:
return
self
.
data
...
...
@@ -61,22 +66,27 @@ class Call:
raise
Exception
(
self
.
error
)
def
join
(
self
):
# type: () -> None
self
.
t
.
join
()
@
classmethod
def
resolve
(
cls
,
value
:
T
):
def
resolve
(
cls
,
value
):
# type: (T) -> Call
return
Call
(
lambda
res
,
rej
:
res
(
value
))
@
classmethod
def
reject
(
cls
,
error
:
E
):
def
reject
(
cls
,
error
):
# type: (E) -> Call
return
Call
(
lambda
res
,
rej
:
rej
(
error
))
def
_on_resolve
(
self
,
data
:
T
):
def
_on_resolve
(
self
,
data
):
# type: (T) -> None
self
.
data
=
data
self
.
error
=
None
self
.
status
=
self
.
RESOLVED
def
_on_rejected
(
self
,
error
:
E
):
def
_on_rejected
(
self
,
error
):
# type: (E) -> None
self
.
error
=
error
self
.
data
=
None
self
.
status
=
self
.
REJECTED
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