friendlyhj/ZenUtils

Сatenation MC stall

Closed this issue · 3 comments

After updating to new version and using new catenation api, i encounter MC window unresponding.

This happen when i firstly subscribe to events.onPlayerLoggedIn, then create new catenation with sleeps

e.player.world.catenation().sleep(100).then(function(world) {
    print('First then');
  })
  
  .sleep(300).then(function(world) {
    print('Second then');
    runAutomation(e.player);
  }).start();

and then create another inside

function runAutomation(player as IPlayer) as void {
  print('runAutomation');
  player.world.catenation().sleep(20).then(function(world) {
    print('First catenation');
  }).start();
  print('end');

Output looks like this:

First then
Second then
runAutomation
end

And then MC window hang unresponding.

Crash Report:

java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
    at java.util.ArrayList$Itr.next(ArrayList.java:851)
    at com.google.common.collect.AbstractMapBasedMultimap$WrappedCollection$WrappedIterator.next(AbstractMapBasedMultimap.java:496)
    at java.util.Collection.removeIf(Collection.java:414)
    at youyihj.zenutils.impl.util.catenation.CatenationManager.onWorldTick(CatenationManager.java:25)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_1841_CatenationManager_onWorldTick_WorldTickEvent.invoke(.dynamic)

Logs

crash-2022-08-05_09.02.37-server.txt
debug.log

Although I fixed the issue, I doubted why you did this. I think it is because you can't share data between catenation tasks. So I add CatenationContext to implement this feature in version 1.11.2.

This means you can do...

e.player.world.catenation().sleep(100).then(function(world, context) {
    print('First then');
  })
  .sleep(300).then(function(world, context) {
    context.data = true; // the data is an `IData`, boolean should be implicitly cast to IData
    print('Second then');
  })
   .sleep(20).then(function(world, context) {
     if (context.data.asBool()) {
        print('First catenation');
     }
  }).start();

Yep, new context argument to these functions. It is a breaking change.

runAutomation() function called with command manager. So i need this function to be called from two places.
I don't understand actually why i should use context.

So I thought wrong before, but it's a good feature anyway. 😅