Talk:CoroutineScheduler

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(New page: = RemoveCoroutine = You have some redundancy in your RemoveCoroutine function. If you're not the head of the list (you are not the first) there have to be a previous node. So it could be s...)
 
(RemoveCoroutine: Found another flaw in the "First" case.)
 
Line 1: Line 1:
 
= RemoveCoroutine =
 
= RemoveCoroutine =
You have some redundancy in your RemoveCoroutine function. If you're not the head of the list (you are not the first) there have to be a previous node. So it could be simplified to:
+
You have some redundancy in your RemoveCoroutine function. If you're not the head of the list (you are not the first) there have to be a previous node. Also if you're the first node you have to check if there's a successor and you have to set it to null as well. Otherwise it will exist until the list is empty.
 +
 
 +
So it could be simplified to:
  
 
<javascript>
 
<javascript>
 
   if (first == coroutine) { // remove first
 
   if (first == coroutine) { // remove first
 
       first = coroutine.listNext;
 
       first = coroutine.listNext;
   } else { // not head of list
+
   } else { // we have a predecessor
 
       coroutine.listPrevious.listNext = coroutine.listNext;
 
       coroutine.listPrevious.listNext = coroutine.listNext;
      if (coroutine.listNext != null) { // we have a successor
 
          coroutine.listNext.listPrevious = coroutine.listPrevious;
 
      }
 
 
   }
 
   }
 +
  if (coroutine.listNext != null) { // we have a successor
 +
      coroutine.listNext.listPrevious = coroutine.listPrevious;
 +
  }
 +
 
</javascript>
 
</javascript>
  
 
However, really nice example, i think that will help beginners a lot. Too bad you can't upvote in the wiki ;)
 
However, really nice example, i think that will help beginners a lot. Too bad you can't upvote in the wiki ;)
 
--[[User:Bunny83|Bunny83]] 18:40, 17 April 2011 (PDT)
 
--[[User:Bunny83|Bunny83]] 18:40, 17 April 2011 (PDT)

Latest revision as of 04:24, 18 April 2011

[edit] RemoveCoroutine

You have some redundancy in your RemoveCoroutine function. If you're not the head of the list (you are not the first) there have to be a previous node. Also if you're the first node you have to check if there's a successor and you have to set it to null as well. Otherwise it will exist until the list is empty.

So it could be simplified to:

<javascript>

 if (first == coroutine) { // remove first
     first = coroutine.listNext;
 } else { // we have a predecessor
     coroutine.listPrevious.listNext = coroutine.listNext;
 }
 if (coroutine.listNext != null) { // we have a successor
     coroutine.listNext.listPrevious = coroutine.listPrevious;
 }

</javascript>

However, really nice example, i think that will help beginners a lot. Too bad you can't upvote in the wiki ;) --Bunny83 18:40, 17 April 2011 (PDT)

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox