Skip to content

Instantly share code, notes, and snippets.

View ptdecker's full-sized avatar

Peter Todd Decker ("Todd") ptdecker

  • Kansas City
View GitHub Profile
@ptdecker
ptdecker / control-flow-3.js
Last active December 6, 2016 15:05
Node.js Rate Limited Concurrent Execution of an Async Function
/* Control Flow 3 - Rate Limited Concurrent Execution of an Asynchronous Function
*
* Based on:
* - http://book.mixu.net/node/ch7.html
* - https://github.com/mixu
*
* Characteristics:
* - Runs a number of operations concurrently
* - Starts a limited number of operations concurrently (partial concurrency, full concurrency control)
* - No guarantee of order, only that all the operations have been completed
@ptdecker
ptdecker / control-flow-2.js
Last active December 6, 2016 15:05
Node.js Fully Concurrent Execution of an Async Function without Rate Limiting
/* Control Flow 2 - Fully Concurrent Executions of a Function (not rate limited)
*
* Based on:
* - http://book.mixu.net/node/ch7.html
* - https://github.com/mixu
*
* Characteristics:
*
* - Runs a number of operations concurrently
* - Starts all async operations near simultaneously (full concurrency)
@ptdecker
ptdecker / control-flow-1.js
Last active November 12, 2024 17:37
Node.js Serial Execution of an Async Function
/* Control Flow 1 - Repetitive Serial Execution of an Asynchronous Function
*
* Based on:
* - http://book.mixu.net/node/ch7.html
* - https://github.com/mixu
*
* Revised to use "typeof(first_item) != 'undefined'" based upon comments from 'Israel'
*
* Characteristics:
* - Flow control construct 'series' is recursive
@ptdecker
ptdecker / net-watcher-v2.js
Created August 20, 2014 23:26
Automatically cleaning up a socket on Ubuntu 14.04 when 'Ctrl-C' is used to terminate node.js
/* This addresses a problem with the 'net-watcher.js' example in Jim Wilson's
* "Node.js The Right Way" book when running his 'net-watcher.js' example under
* Ubuntu 14.04 (and probably some other *nixs too).
*/
'use strict';
const
fs = require('fs'),
net = require('net'),