GeezerVison is showing github.com — embedding: make Stop() stop Workers · cheza24/node@037ac99
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/api/environment.cc +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -725,8 +725,7 @@ ThreadId AllocateEnvironmentThreadId() { |
725 | 725 | } |
726 | 726 |
|
727 | 727 | void DefaultProcessExitHandler(Environment* env, int exit_code) { |
728 | | - env->set_can_call_into_js(false); |
729 | | - env->stop_sub_worker_contexts(); |
| 728 | + Stop(env); |
730 | 729 | DisposePlatform(); |
731 | 730 | exit(exit_code); |
732 | 731 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: src/env.cc +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -501,9 +501,10 @@ void Environment::InitializeLibuv(bool start_profiler_idle_notifier) { |
501 | 501 | } |
502 | 502 | } |
503 | 503 |
|
504 | | -void Environment::ExitEnv() { |
| 504 | +void Environment::Stop() { |
505 | 505 | set_can_call_into_js(false); |
506 | 506 | set_stopping(true); |
| 507 | + stop_sub_worker_contexts(); |
507 | 508 | isolate_->TerminateExecution(); |
508 | 509 | SetImmediateThreadsafe([](Environment* env) { uv_stop(env->event_loop()); }); |
509 | 510 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: src/env.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -897,7 +897,7 @@ class Environment : public MemoryRetainer { |
897 | 897 | void RegisterHandleCleanups(); |
898 | 898 | void CleanupHandles(); |
899 | 899 | void Exit(int code); |
900 | | - void ExitEnv(); |
| 900 | + void Stop(); |
901 | 901 |
|
902 | 902 | // Register clean-up cb to be called on environment destruction. |
903 | 903 | inline void RegisterHandleCleanup(uv_handle_t* handle, |
|
Collapse file
Copy file name to clipboardExpand all lines: src/node.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1059,7 +1059,7 @@ int Start(int argc, char** argv) { |
1059 | 1059 | } |
1060 | 1060 |
|
1061 | 1061 | int Stop(Environment* env) { |
1062 | | - env->ExitEnv(); |
| 1062 | + env->Stop(); |
1063 | 1063 | return 0; |
1064 | 1064 | } |
1065 | 1065 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: src/node.h +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -224,7 +224,8 @@ class Environment; |
224 | 224 | NODE_EXTERN int Start(int argc, char* argv[]); |
225 | 225 |
|
226 | 226 | // Tear down Node.js while it is running (there are active handles |
227 | | -// in the loop and / or actively executing JavaScript code). |
| 227 | +// in the loop and / or actively executing JavaScript code). This also stops |
| 228 | +// all Workers that may have been started earlier. |
228 | 229 | NODE_EXTERN int Stop(Environment* env); |
229 | 230 |
|
230 | 231 | // TODO(addaleax): Officially deprecate this and replace it with something |
@@ -478,8 +479,8 @@ NODE_EXTERN void FreeEnvironment(Environment* env); |
478 | 479 | // It receives the Environment* instance and the exit code as arguments. |
479 | 480 | // This could e.g. call Stop(env); in order to terminate execution and stop |
480 | 481 | // the event loop. |
481 | | -// The default handler disposes of the global V8 platform instance, if one is |
482 | | -// being used, and calls exit(). |
| 482 | +// The default handler calls Stop(), disposes of the global V8 platform |
| 483 | +// instance, if one is being used, and calls exit(). |
483 | 484 | NODE_EXTERN void SetProcessExitHandler( |
484 | 485 | Environment* env, |
485 | 486 | std::function<void(Environment*, int)>&& handler); |
|