From 0087bc6370c440fad0d8fc61515a7c02e9f8ae1b Mon Sep 17 00:00:00 2001 From: Pooya Karimian Date: Fri, 17 Aug 2012 13:57:23 -0700 Subject: [PATCH] cluster.worker description and examples ere missing from the top level of docs --- doc/api/cluster.markdown | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/api/cluster.markdown b/doc/api/cluster.markdown index aa59acbf48a..032e38138e2 100644 --- a/doc/api/cluster.markdown +++ b/doc/api/cluster.markdown @@ -252,12 +252,29 @@ die graceful if no other event is waiting. The method takes an optional callback argument which will be called when finished. +## cluster.worker + +* {Object} + +A reference to the current worker object. Not available in the master process. + + var cluster = require('cluster'); + + if (cluster.isMaster) { + console.log('I am master'); + cluster.fork(); + cluster.fork(); + } else if (cluster.isWorker) { + console.log('I am worker #' + cluster.worker.id); + } + ## cluster.workers * {Object} A hash that stores the active worker objects, keyed by `id` field. Makes it -easy to loop through all the workers. +easy to loop through all the workers. It is only available in the master +process. // Go through all workers function eachWorker(callback) {