Example #1
0
// New creates a new worker, which corresponds to a V8 isolate. A single threaded
// standalone execution context.
func New(cb ReceiveMessageCallback, syncCB ReceiveSyncMessageCallback) *Worker {
	id := nextWorkerId()

	cbWrapper := &callbacks{
		cb:     cb,
		syncCB: syncCB,
	}
	callbacksMapLocker.Lock()
	callbacksMap[id] = cbWrapper
	callbacksMapLocker.Unlock()

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

	worker := &Worker{}
	worker.cWorker = C.worker_new(C.int(id))
	runtime.SetFinalizer(worker, func(final_worker *Worker) {
		C.worker_dispose(final_worker.cWorker)
		callbacksMapLocker.Lock()
		delete(callbacksMap, id)
		callbacksMapLocker.Unlock()
	})
	return worker
}
Example #2
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
}
Example #3
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
}