| Conditions | 1 |
| Paths | 1 |
| Total Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* global VoxEngine, AppEvents */ |
||
| 25 | VoxEngine.addEventListener(AppEvents.Started, function (event) { |
||
| 26 | logger.info('Ok, let\'s get started') |
||
| 27 | logger.info('Incoming event was: {}', event) |
||
| 28 | logger.error('Printing fake error:', new Error()) |
||
| 29 | logger.debug('Debug level has been hidden - minimum required level is INFO') |
||
| 30 | |||
| 31 | logger.info('The first thing to do is to check https://ya.ru content') |
||
| 32 | logger.info('I bet it hasn\'t changed yet') |
||
| 33 | var simpleRequest = queue.push(function () { return http.get('/') }) |
||
| 34 | simpleRequest.then(function (response) { |
||
| 35 | logger.info('ya.ru response: {}', response) |
||
| 36 | logger.info( |
||
| 37 | 'Chances are, above output has been truncated - ' + |
||
| 38 | 'that\'s because VoxEngine\'s logger is still used under hood' |
||
| 39 | ) |
||
| 40 | }) |
||
| 41 | |||
| 42 | logger.info('Next, let\'s check which tags are present for current repo') |
||
| 43 | logger.info( |
||
| 44 | 'Most probably GitHub will return error 403, so HTTP client will spin' + |
||
| 45 | 'until it will spend all retries it has been configured with' |
||
| 46 | ) |
||
| 47 | logger.info( |
||
| 48 | 'Please note that task will be registered but not executed until ' + |
||
| 49 | 'first request has finished' |
||
| 50 | ) |
||
| 51 | var tags = queue.push( |
||
| 52 | function () { return rest.get('/tags') }, |
||
| 53 | {name: 'Retrieving list of ama-team/voxengine-sdk tags'} |
||
| 54 | ) |
||
| 55 | tags.then(function (tags) { |
||
| 56 | tags = tags.map(function (entry) { return entry.name }) |
||
| 57 | logger.info('Found tags for current repo: {}', tags) |
||
| 58 | }, function (error) { |
||
| 59 | logger.error('GitHub didn\'t let me to query his API: ', error) |
||
| 60 | }) |
||
| 61 | |||
| 62 | logger.info( |
||
| 63 | 'Finally, let\'s register task that will instantly time out ' + |
||
| 64 | 'and produce TimeoutException' |
||
| 65 | ) |
||
| 66 | var failure = queue.push(function () { |
||
| 67 | return rest.get('/contributors', {}, {}, 0) |
||
| 68 | }) |
||
| 69 | failure |
||
| 70 | .then(function () { |
||
| 71 | logger.error( |
||
| 72 | 'Wow! The request has finished in less than one nodejs tick, guys, ' + |
||
| 73 | 'have you been mocking globals?' |
||
| 74 | ) |
||
| 75 | }, function (error) { |
||
| 76 | logger.warn('Impossible request expectedly ended with error {}', |
||
| 77 | error.name) |
||
| 78 | }) |
||
| 79 | .then(function () { |
||
| 80 | logger.info( |
||
| 81 | 'Please note again that this task has started only after ' + |
||
| 82 | 'previous one has finished' |
||
| 83 | ) |
||
| 84 | }) |
||
| 85 | |||
| 86 | logger.info( |
||
| 87 | 'All tasks have been registered at this moment. Let\'s close task queue, ' + |
||
| 88 | 'and, when last task is done, shut down VoxEngine' |
||
| 89 | ) |
||
| 90 | queue |
||
| 91 | .close() |
||
| 92 | .then(function () { |
||
| 93 | logger.notice('All tasks have finished, shutting down the engine') |
||
| 94 | }) |
||
| 95 | .then(VoxEngine.terminate.bind(VoxEngine)) |
||
| 96 | }) |
||
| 97 |