Git Product home page Git Product logo

Comments (3)

CrazyInfin8 avatar CrazyInfin8 commented on June 11, 2024

I don't think there is currently a way to force a running wren script to terminate prematurely. However, in a fork I created, I hacked in a function to exit the VM here.

Essentially I added a new boolean value to the WrenVM struct called earlyExit which is checked each instruction cycle for the VM. If earlyExit was ever set to true while the VM is still executing code, it raises a runtime error. This way, in another thread, you can set this value (in my implementation using a function called wrenEarlyExit) to effectively stop the VM by the next instruction.

I don't know if this is actually the most optimal way to do this. You'll need another thread running to call the function to stop the VM. I haven't really tested to see whether this is thread safe to begin with, and I also don't know if stopping the VM prematurely might corrupt it or put it in an unusable state. From the few examples I've done with this, the VM seems to interpret and call functions afterwards without issue, though your mileage may vary.

from wren.

luodaoyi avatar luodaoyi commented on June 11, 2024

I don't think there is currently a way to force a running wren script to terminate prematurely. However, in a fork I created, I hacked in a function to exit the VM here.

Essentially I added a new boolean value to the WrenVM struct called earlyExit which is checked each instruction cycle for the VM. If earlyExit was ever set to true while the VM is still executing code, it raises a runtime error. This way, in another thread, you can set this value (in my implementation using a function called wrenEarlyExit) to effectively stop the VM by the next instruction.

I don't know if this is actually the most optimal way to do this. You'll need another thread running to call the function to stop the VM. I haven't really tested to see whether this is thread safe to begin with, and I also don't know if stopping the VM prematurely might corrupt it or put it in an unusable state. From the few examples I've done with this, the VM seems to interpret and call functions afterwards without issue, though your mileage may vary.

This solution is very good! but have to edit wren code ..

from wren.

mhermier avatar mhermier commented on June 11, 2024

from wren.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.