Open UXDart opened 6 years ago
hmm.. they are sharing the same JSVirtualMachine... so that makes sense then... that must be the reason right? where is COScript creating the JSVirtualMachine? or how can I create a new one for each COScript instance?
Thanks
found a way to create them with different JSVirtualMachine, so each one has its own Mocha instance, and it happens anyway, threads gets serialised... any tip? TIA!
Are you creating the CocoaScript instances, or is this something that Sketch is handing off to you?
I tried with Sketch ones, didn't work. so I'm creating the instances myself, so I can do whatever is needed to make it work. atm I find a way to create each instance of Mocha inside COScript using a different JSVirtualMachine, using initWithGlobalContext
method. but then nothing works, it seems it can't set a variable there for some reason. I think that is the issue, that Sketch is doing a Mocha.alloc.init so it using the same Mocha global context. it makes sense?
do you have a sample of how to use the method initWithGlobalContext? what do I need to send exactly so it has a different global context?
or what do you think may be the cause of the serialising of the threads?
Thanks!
I'm doing this atm:
JSContext *contextNew = [[JSContext alloc] initWithVirtualMachine:[[JSVirtualMachine alloc] init]]; JSGlobalContextRef globalCtx1 = contextNew.JSGlobalContextRef; _mochaRuntime = [[Mocha alloc] initWithGlobalContext:globalCtx1 name:nil];
but that seems to work, but then the setvalue getvalue doesn't work...
I'm not sure what would be causing it off the top of my head. You might ping the sketch folks.
Hello! I'm writing a plugin for Sketch, and inside the cocoa script I use
performSelectorInBackground_withObject
to start a new thread and don't block the execution of a log running process. that works perfect! I callcoscript.setShouldKeepAround(true);
andcoscript.setShouldKeepAround(false);
when the thread ends. that works ok.the problem is that, if I start (lets say) 3 scripts, different names, different COScript instances, this happens:
so for some reason it seems something is making them stop/wait when other thread is working. I know COScript does not really support threads, but they work... in some way... the question is, why this could be happening? I tried many things, but in all cases this happens. if someone has any tip I can work over that, but I just don't know what else to try... thx!
TIA!