Comments (8)
Ideally sending from multiple goroutines would work, but I haven't tested it. It might need a lock.
Killing a worker could be done with a call to v8::Isolate::TerminateExecution()
. Do you need it?
from v8worker.
I will setup such a test (goroutine) as well.
Yes, I need to be able to terminate a worker to protect my program against Javascript errors that result in endless loops or other disasters. My application can load and run arbitrary Javascript code and typically during development of that code, mistakes are made. I would like my application to recover from that without restart.
from v8worker.
@emicklei I spent a little time trying to get kill working. It doesn't work yet. But maybe you can make more progress with this? https://gist.github.com/ry/1f0656fe15c229c0aa45
from v8worker.
Thank you for working on this request. I will look at it as well.
from v8worker.
not related but probably of interest to you, I created a fork in which I added another builtin function for synchronous message exchange. I realize that this is "against" your original clean design of message passing but I needed it to replace my existing otto based solution. I got this extension working now but it also needs more testing.
from v8worker.
Why do you need that? I'm not against adding something like that if there's a necessary use case. It's a call from js that send a message to go and returns the response?
from v8worker.
In Javascript, I expose several objects that represent an api written in Go. At the time of its design, most api operations were synchronous and could be mapped to function calls of their Go counterpart. These operations include state access of a large object structure (physics engine).
I have considered changing my api design but that would obviously break all existing programs. So instead, I was looking for a construct that could emulate the behavior using send and recv. With the current implementation, I don't see how I can send a message and wait for the receive to happen and return the value encoded by the message. (even Promises require callback functions).
With this additional request-response feature, I can use these values for transport
type MessageSend struct {
Receiver string `json:"receiver" `
Method string `json:"method" `
Arguments []interface{} `json:"args" `
}
which can be dispatched on both sides. For example utils.now()
is translated to a MessageSend with receiver utils
, method now
. On the Go side, I have registered a Module value by the name of utils
and have a Dispatch(MessageSend) function that performs a function lookup (case) and invocation. A similar mechanism is implemented in Javascript for calling from Go (currently without scoping).
$recv(function(msg) {
var obj = JSON.parse(msg);
this[obj.method].apply(this, obj.args)
});
The response of a Go Dispatch(msg) will be an interface{} value encoded in JSON before returning to v8worker and to the caller in Javascript.
Because the flow is now synchronous, when an error happens on the Go side, I can report that to the developers too (using the console
Module) complete with stack information (file:line).
There are many other details to this story but this is basically how I intend to use the package.
from v8worker.
( off topic ) fyi, I just published a package implementing this idea. https://godoc.org/github.com/emicklei/v8dispatcher
from v8worker.
Related Issues (20)
- build with Docker HOT 2
- Slow compile time HOT 6
- Have you seen Nim HOT 1
- cannot compile HOT 2
- synchronuous calls, Go <-> Js HOT 4
- A way to destroy a worker HOT 1
- Support building the entire project using only the `go build` command HOT 2
- Go 1.6 is more strict: cgo argument has Go pointer to Go pointer HOT 5
- Migrating from Otto to v8worker HOT 6
- Workers not GCed when in tight loop HOT 13
- Debug JavaScript runtime errors
- Build failed -- unsupported reloc 42 against global symbol __gmon_start__ HOT 9
- One else memory leak fix HOT 1
- Can't build package because it contains C++ files (binding.cc) but it's not using cgo nor SWIG HOT 2
- Global`window` object not available; nor "built-in" functions HOT 3
- Add support for node module loading HOT 1
- Questions: cloning, binary size, namespace
- `make GYPFLAGS="-Dcomponent=shared_library"` fails to build target 'v8worker.test'
- Observing strange issue with SendSync HOT 2
- Running: gclient sync --nohooks --with_branch_heads
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from v8worker.