Promises seem to bypass CPU limits



  • If I run `Promise.resolve(true).then(myFunc)`, `myFunc` will run *after* all intents have been collected and all CPU usage has been recorded. This allows `myFunc` to run up until the `vm.runInContext` timeout kills the context, and the extra burned CPU won't be counted against my bucket.

    Since all of the intents have been collected, you can't do anything except set variables. However, because contexts are reused between ticks, a future tick on the same worker can notice these updated variables. This enables you to do things like complex pathfinding without dealing with CPU limitations.

    Obviously this CPU isn't free for anybody, but at the same time Promise is exposed to the generated code. Is there an official stance as to whether this is within the rules of the game?



  •  Wow. Heavy stuff.

     

    Would be curious to know myself.



  • Any update on this?

     

    There seems to be a PR for the Private Server driver at https://github.com/screeps/driver/pull/6 which would fix this, could a similar fix be applied to the main servers?


  • Dev Team

    The PR is merged, thanks for contributing.