This repository has been archived by the owner on May 31, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import asyncio | ||
|
||
|
||
async def multiply(x): | ||
result = x * 2 | ||
await asyncio.sleep(1) | ||
return result | ||
|
||
|
||
async def steps(x): | ||
result = await multiply(x) | ||
print("result: %s" % result) | ||
|
||
|
||
loop = asyncio.get_event_loop() | ||
coro = steps(5) | ||
loop.run_until_complete(coro) | ||
loop.close() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from twisted.internet import defer | ||
from twisted.internet import reactor | ||
|
||
|
||
def multiply(x): | ||
result = x * 2 | ||
d = defer.Deferred() | ||
reactor.callLater(1.0, d.callback, result) | ||
return d | ||
|
||
|
||
def step1(x): | ||
return multiply(x) | ||
|
||
|
||
def step2(result): | ||
print("result: %s" % result) | ||
|
||
reactor.stop() | ||
|
||
|
||
d = defer.Deferred() | ||
d.addCallback(step1) | ||
d.addCallback(step2) | ||
d.callback(5) | ||
|
||
reactor.run() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters