[READ-ONLY] Mirror of https://github.com/thoda-dev/du-nested-coroutines. A small script for DU to avoid any CPU load error
0

Configure Feed

Select the types of activity you want to include in your feed.

credits

Thomas (Jul 11, 2021, 1:29 PM +0200) 8be67681 96c0293e

+14 -2
+6
Source/unit/start.lua
··· 1 + --[[ 2 + DU-Nested-Coroutines by Jericho 3 + Permit to easier avoid CPU Load Errors 4 + Source available here: https://github.com/Jericho1060/du-nested-coroutines 5 + ]]-- 6 + 1 7 coroutinesTable = {} 2 8 --all functions here will become a coroutine 3 9 MyCoroutines = {
+6
Source/update/update.lua
··· 1 + --[[ 2 + DU-Nested-Coroutines by Jericho 3 + Permit to easier avoid CPU Load Errors 4 + Source available here: https://github.com/Jericho1060/du-nested-coroutines 5 + ]]-- 6 + 1 7 if coroutine.status(MainCoroutine) == "dead" then 2 8 MainCoroutine = coroutine.create(runCoroutines) 3 9 end
+2 -2
config.json
··· 94 94 }, 95 95 "handlers": [ 96 96 { 97 - "code": "coroutinesTable = {}\n--all functions here will become a coroutine\nMyCoroutines = {\n function()\n for i=0, 10 do\n system.print(\"function 1 --- \"..i)\n coroutine.yield(coroutinesTable[1])--start with index 1 and so on\n end\n end,\n function()\n for i=0, 10 do\n system.print(\"function 2 --- \"..i)\n coroutine.yield(coroutinesTable[2])--the second fonction yiel is with index 2\n end\n end\n}\n\nfunction initCoroutines()\n for _,f in pairs(MyCoroutines) do\n local co = coroutine.create(f)\n table.insert(coroutinesTable, co)\n end\nend\n\ninitCoroutines()\n\nrunCoroutines = function()\n for i,co in ipairs(coroutinesTable) do\n if coroutine.status(co) == \"dead\" then\n coroutinesTable[i] = coroutine.create(MyCoroutines[i])\n end\n if coroutine.status(co) == \"suspended\" then\n assert(coroutine.resume(co))\n end\n end\nend\n\nMainCoroutine = coroutine.create(runCoroutines)", 97 + "code": "--[[\n DU-Nested-Coroutines by Jericho\n Permit to easier avoid CPU Load Errors\n Source available here: https://github.com/Jericho1060/du-nested-coroutines\n]]--\n\ncoroutinesTable = {}\n--all functions here will become a coroutine\nMyCoroutines = {\n function()\n for i=0, 10 do\n system.print(\"function 1 --- \"..i)\n coroutine.yield(coroutinesTable[1])--start with index 1 and so on\n end\n end,\n function()\n for i=0, 10 do\n system.print(\"function 2 --- \"..i)\n coroutine.yield(coroutinesTable[2])--the second fonction yiel is with index 2\n end\n end\n}\n\nfunction initCoroutines()\n for _,f in pairs(MyCoroutines) do\n local co = coroutine.create(f)\n table.insert(coroutinesTable, co)\n end\nend\n\ninitCoroutines()\n\nrunCoroutines = function()\n for i,co in ipairs(coroutinesTable) do\n if coroutine.status(co) == \"dead\" then\n coroutinesTable[i] = coroutine.create(MyCoroutines[i])\n end\n if coroutine.status(co) == \"suspended\" then\n assert(coroutine.resume(co))\n end\n end\nend\n\nMainCoroutine = coroutine.create(runCoroutines)", 98 98 "filter": { 99 99 "args": [], 100 100 "signature": "start()", ··· 103 103 "key": "0" 104 104 }, 105 105 { 106 - "code": "if coroutine.status(MainCoroutine) == \"dead\" then\n MainCoroutine = coroutine.create(runCoroutines)\nend\nif coroutine.status(MainCoroutine) == \"suspended\" then\n assert(coroutine.resume(MainCoroutine))\nend", 106 + "code": "--[[\n DU-Nested-Coroutines by Jericho\n Permit to easier avoid CPU Load Errors\n Source available here: https://github.com/Jericho1060/du-nested-coroutines\n]]--\n\nif coroutine.status(MainCoroutine) == \"dead\" then\n MainCoroutine = coroutine.create(runCoroutines)\nend\nif coroutine.status(MainCoroutine) == \"suspended\" then\n assert(coroutine.resume(MainCoroutine))\nend", 107 107 "filter": { 108 108 "args": [], 109 109 "signature": "update()",