Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Get rid of returning values as callback argument in really synchronous functions #164

Closed
wants to merge 1 commit into from

3 participants

@ayatkevich
  • Group#count
  • Group#getUsers
  • Group#hasClient
  • User#getGroups
  • nowjs#getGroups

This should make code cleaner.

@ayatkevich ayatkevich Removed asynchronous pattern from the really synchronous functions:
* Group#count
* Group#getUsers
* Group#hasClient
* User#getGroups
* nowjs#getGroups
a9dc3ce
@steveWang

This design decision was made to maintain feature parity with Cluster, in which these functions can only be implemented as async.

@ericz

Hi ayatkevich,

Unfortunately we have to keep asynchronous for the reasons steve mentioned above.
Thank you for the pull request though!

@ericz ericz closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 12, 2011
  1. @ayatkevich

    Removed asynchronous pattern from the really synchronous functions:

    ayatkevich authored
    * Group#count
    * Group#getUsers
    * Group#hasClient
    * User#getGroups
    * nowjs#getGroups
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 23 deletions.
  1. +10 −12 lib/group.js
  2. +5 −7 lib/now.js
  3. +4 −4 lib/user.js
View
22 lib/group.js
@@ -50,15 +50,14 @@ exports.initialize = function (nowjs) {
* @description Used to find the cardinality of the group (how
* many users it contains).
- * @param {Function} callback Called with a Number corresponding to
- * the group's user count.
+ * @return {Number} A number corresponding to the group's user count.
* @example everyone.count(function (ct) {
* console.log(ct);
* });
*/
- Group.prototype.count = function (callback) {
- callback(Object.keys(this.users).length);
+ Group.prototype.count = function () {
+ return Object.keys(this.users).length;
};
/**
@@ -69,8 +68,8 @@ exports.initialize = function (nowjs) {
* @description Used to retrieve a list of the client IDs
* corresponding to all users in the group.
- * @param {Function} callback Called with an Array of Strings
- * corresponding to the client IDs of all users in the group.
+ * @return {Array} An Array of Strings corresponding to the client IDs of all
+ * users in the group.
* @example everyone.getUsers(function (users) {
* for (var i = 0; i < users.length; i++) console.log(users[i]);
@@ -78,8 +77,8 @@ exports.initialize = function (nowjs) {
* @see nowjs#getClient
*/
- Group.prototype.getUsers = function (callback) {
- callback(Object.keys(this.users));
+ Group.prototype.getUsers = function () {
+ return Object.keys(this.users);
};
/**
@@ -267,8 +266,7 @@ exports.initialize = function (nowjs) {
* @param {String} clientId The client ID associated with the target
* user.
- * @param {Function} callback Called with a Boolean indicating the
- * user's membership in the group.
+ * @return {Boolean} indicating the user's membership in the group.
* @example group.hasClient('1234567890', function (bool) {
* if (bool) {
@@ -276,8 +274,8 @@ exports.initialize = function (nowjs) {
* }
* });
*/
- Group.prototype.hasClient = function (clientId, callback) {
- callback(this.users[clientId] !== undefined);
+ Group.prototype.hasClient = function (clientId) {
+ return this.users[clientId] !== undefined;
};
/**
View
12 lib/now.js
@@ -70,8 +70,7 @@ Now.prototype.getClient = function (id, callback) {
* array) of all groups that have been created and passes it in to the
* supplied callback.
- * @param {Function} callback Takes one argument, an array of all
- * groups that have been created.
+ * @return {Array} an array of all groups that have been created.
* @example nowjs.on('connect', function () {
* var self = this;
@@ -80,8 +79,8 @@ Now.prototype.getClient = function (id, callback) {
* });
* });
*/
-Now.prototype.getGroups = function (callback) {
- callback(Object.keys(this.groups));
+Now.prototype.getGroups = function () {
+ return Object.keys(this.groups);
};
/**
@@ -183,9 +182,8 @@ Now.prototype.initialize = function (server, options) {
};
Now.prototype.addSupportServer = function(host, port){
- var server = new this.Support(host, port);
- return server;
-}
+ return new this.Support(host, port);
+};
exports.Now = Now;
View
8 lib/user.js
@@ -158,8 +158,8 @@ exports.initialize = function (nowjs) {
* @description Used to retrieve a list of the group names
* corresponding to all groups the user is in.
- * @param {Function} callback Called with an Array of Strings
- * corresponding to the various group names.
+ * @return {Array} an Array of Strings corresponding to the various group
+ * names.
* @example everyone.now.broadcast = function (message) {
* var name = this.now.name;
@@ -171,8 +171,8 @@ exports.initialize = function (nowjs) {
* }
* });
*/
- User.prototype.getGroups = function (callback) {
- callback(Object.keys(this.groups));
+ User.prototype.getGroups = function () {
+ return Object.keys(this.groups);
};
/** @private */
Something went wrong with that request. Please try again.