Update race_behaviours.py - #2
Open
Margravegit wants to merge 1 commit into
Open
Margravegit wants to merge 1 commit into
Margravegit wants to merge 1 commit into
Conversation
Added fullstop behavior
Owner
|
Looking Good! |
jazzz
reviewed
Mar 15, 2018
|
|
||
| async def update(self): | ||
| while True: | ||
| await asyncio.sleep(0.1) |
Owner
There was a problem hiding this comment.
While this works great, with co-routines we can simplify things by removing the conditional logic. In a coroutine when you 'await' you are suspending the function, so it resumes where it left off.
async def update():
n = 255
while True:
for x in range(n+1):
await asyncio.sleep(0.1)
self.color = Color(x,0,0)
for x in range(n-1,0,-1):
await asyncio.sleep(0.1)
self.color = Color(x,0,0)Better yet we could also do something like if you wanted to reuse the functionality.
async def update():
async for x in thereAndBackIncrementor(0,10):
self.color = Color(x,0,0)
await asyncio.sleep(0.1)
async def thereAndBackIncrementor(firstVal,lastVal):
for x in range(lastVal + 1):
yield x
for x in range(lastVal - 1, firstVal, -1):
yield x
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added fullstop behavior