Skip to content

Instantly share code, notes, and snippets.

@deepal
Created October 15, 2019 21:32
Show Gist options
  • Save deepal/18c7d9eadc504b731316bdc0a4e257c7 to your computer and use it in GitHub Desktop.
Save deepal/18c7d9eadc504b731316bdc0a4e257c7 to your computer and use it in GitHub Desktop.
Create message port between parent and child thread
void Worker::CreateEnvMessagePort(Environment* env) {
HandleScope handle_scope(isolate_);
Mutex::ScopedLock lock(mutex_);
// Set up the message channel for receiving messages in the child.
child_port_ = MessagePort::New(env,
env->context(),
std::move(child_port_data_));
// MessagePort::New() may return nullptr if execution is terminated
// within it.
if (child_port_ != nullptr)
env->set_message_port(child_port_->object(isolate_));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment