Exemplo n.º 1
0
// Creates a new worker, which corresponds to a V8 isolate. A single threaded
// standalone execution context.
func New(cb ReceiveMessageCallback) *Worker {
	worker := &Worker{
		cb: cb,
	}

	initV8Once.Do(func() {
		C.v8_init()
	})

	callback := C.worker_recv_cb(C.go_recv_cb)

	worker.cWorker = C.worker_new(callback, unsafe.Pointer(worker))
	return worker
}
Exemplo n.º 2
0
// Creates a new worker, which corresponds to a V8 isolate. A single threaded
// standalone execution context.
func New(cb ReceiveMessageCallback, recvSync_cb ReceiveSyncMessageCallback) *Worker {
	worker := &Worker{
		cb:          cb,
		recvSync_cb: recvSync_cb,
	}

	initV8Once.Do(func() {
		C.v8_init()
	})

	callback := C.worker_recv_cb(C.go_recv_cb)
	receiveSync_callback := C.worker_recvSync_cb(C.go_recvSync_cb)

	worker.cWorker = C.worker_new(callback, receiveSync_callback, unsafe.Pointer(worker))
	runtime.SetFinalizer(worker, func(final_worker *Worker) {
		C.worker_dispose(final_worker.cWorker) // Delete this worker on finalize (GC)
	})
	return worker
}