How to sync libuv code?

There is a simple example (below). The problem is that I need within the process to wait for the completion code in the after, how it correctly to implement? Not the while loop at the end of the same-all to do?
uv_work_t *baton;

void work(uv_work_t* task) {}

void after(uv_work_t* task, int status) {
printf("after\n");
 delete task;
}

int process()
{
 baton = new uv_work_t();
 uv_queue_work(uv_default_loop(), baton work, after);
printf("before\n");
 return 0;
}

P. S. the process runs in a separate thread using pthread.
September 26th 19 at 11:52
1 answer
September 26th 19 at 11:54
Solution
To have a semaphore (uv_sem_*), which is to expect in the process and pulling in after. Like that:
static uv_sem_t sem;
uv_work_t *baton;

void work(uv_work_t* task) {}

void after(uv_work_t* task, int status) {
printf("after\n");
 delete task;
uv_sem_post(&sem);
}
int process()
{
 baton = new uv_work_t();
 if (uv_sem_init(&sem, 0) < 0) {
perror("uv_sem_init");
 return -1;
}
 uv_queue_work(uv_default_loop(), baton work, after);
printf("before\n");
uv_sem_wait(&sem);
uv_sem_destroy(&sem);
 return 0;
}


But the question arises: what for to use asynchronous framework, where you need synchronous execution of the work? Couldn't you just call work from the process?
Can I get a small code example? How does it "wait"?

> "Couldn't you just call work from the process?"
No, because there is Node.JS code. Get segfault. - Miracle.Bahringer62 commented on September 26th 19 at 11:57
> Possible a small example code?
led.

>> "Couldn't you just call work from the process?"
> No, because there is Node.JS code.
don't see the connection, but you probably know better. - mallie.Carter commented on September 26th 19 at 12:00
thank you! What you need! Task related with toster.ru/q/114557, just call it from the process — get segfault. - Miracle.Bahringer62 commented on September 26th 19 at 12:03

Find more questions by tags C++Node.js