Skip to content

Commit

Permalink
v1.16.13. Bugfix. Improvement.
Browse files Browse the repository at this point in the history
- v1.16.13 March 23, 2013
	- `balUtilEvents` changes:
		- `EventEmitterEnhanced` changes:
			- Now works with `once` calls in node 0.10.0
				- Closes
[docpad/docpad#462](docpad/docpad#462)
			- Changed `emitSync` to be an alias to `emitSerial` and `emitAsync`
to be an alias to `emitParallel`
			- Added new `getListenerGroup` function
	- `balUtilFlow` changes:
		- `fireWithOptionalCallback` can now take the method as an array of
`[fireMethod,introspectMethod]`  useful for pesly binds
  • Loading branch information
balupton committed Mar 23, 2013
1 parent 21eaa54 commit a303d0b
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 73 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ install: "npm install"
before_script: "./node_modules/.bin/cake test-prepare"
script: "./node_modules/.bin/cake test"
node_js:
- 0.4
- 0.6
- 0.8
- 0.10
- "0.4"
- "0.6"
- "0.8"
- "0.10"
notifications:
irc:
- "irc.freenode.org#bevry-dev"
Expand Down
10 changes: 10 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## History

- v1.16.13 March 23, 2013
- `balUtilEvents` changes:
- `EventEmitterEnhanced` changes:
- Now works with `once` calls in node 0.10.0
- Closes [bevry/docpad#462](https://github.com/bevry/docpad/issues/462)
- Changed `emitSync` to be an alias to `emitSerial` and `emitAsync` to be an alias to `emitParallel`
- Added new `getListenerGroup` function
- `balUtilFlow` changes:
- `fireWithOptionalCallback` can now take the method as an array of `[fireMethod,introspectMethod]` useful for pesly binds

- v1.16.12 March 18, 2013
- `balUtilFlow` changes:
- `Groups::run` signature changed from no arguments to a single `mode` argument
Expand Down
61 changes: 36 additions & 25 deletions out/lib/events.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions out/lib/flow.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 84 additions & 5 deletions out/test/events.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bal-util",
"version": "1.16.12",
"version": "1.16.13",
"description": "Common utility functions for Node.js used and maintained by Benjamin Lupton",
"homepage": "https://github.com/balupton/bal-util",
"keywords": [
Expand Down Expand Up @@ -45,7 +45,8 @@
"dependencies": {},
"devDependencies": {
"coffee-script": "~1.6.2",
"joe": "~1.1.1"
"joe": "~1.1.1",
"chai": "~1.5.0"
},
"directories": {
"lib": "./out/lib"
Expand Down
52 changes: 26 additions & 26 deletions src/lib/events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,39 @@ debug = false

class EventEmitterEnhanced extends EventEmitter

# Emit a group of listeners asynchronously
# next(err,result,results)
emitAsync: (eventName,data,next) ->
# Get Listener Group
# Fetch the listeners for a particular event as a task group
getListenerGroup: (eventName,data,next) ->
# Get listeners
me = @
listeners = @listeners(eventName)
# Prepare tasks
tasks = new balUtilFlow.Group(next)
# Add the tasks for the listeners
for listener in listeners
tasks.push {listener}, (complete) ->
# Fire the listener, treating the callback as optional
balUtilFlow.fireWithOptionalCallback(@listener,[data,complete])
# Trigger asynchronously
tasks.async()
# Chain
@

# Emit a group of listeners synchronously
# next(err,result,results)
emitSync: (eventName,data,next) ->
# Get listeners
listeners = @listeners(eventName)
# Prepare tasks
tasks = new balUtilFlow.Group(next)

# Add the tasks for the listeners
for listener in listeners
tasks.push {listener}, (complete) ->
balUtilFlow.each listeners, (listener) ->
# Once will actually wrap around the original listener, which isn't what we want for the introspection
# So we must pass fireWithOptionalCallback an array of the method to fire, and the method to introspect
# https://github.com/bevry/docpad/issues/462
# https://github.com/joyent/node/commit/d1b4dcd6acb1d1c66e423f7992dc6eec8a35c544
listener = [listener,listener.listener] if listener.listener

# Bind to the task
tasks.push (complete) ->
# Fire the listener, treating the callback as optional
balUtilFlow.fireWithOptionalCallback(@listener,[data,complete])
# Trigger synchronously
tasks.sync()
# Chain
@
balUtilFlow.fireWithOptionalCallback(listener,[data,complete],me)

# Return
return tasks

# Emit Serial
emitSync: (args...) -> @emitSerial(args...)
emitSerial: (args...) -> @getListenerGroup(args...).run('serial')

# Emit Parallel
emitAsync: (args...) -> @emitParallel(args...)
emitParallel: (args...) -> @getListenerGroup(args...).run('parallel')


# =====================================
Expand Down
10 changes: 7 additions & 3 deletions src/lib/flow.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ balUtilFlow =
callback = args[args.length-1]
context or= null
result = null
if balUtilTypes.isArray(method)
[fireMethod,introspectMethod] = method
else
fireMethod = introspectMethod = method

# We have the callback
# assume it is async
if method.length is args.length
if introspectMethod.length is args.length
# Fire the function
try
result = method.apply(context,args)
result = fireMethod.apply(context,args)
catch caughtError
callback(caughtError)

Expand All @@ -54,7 +58,7 @@ balUtilFlow =

# Fire the function
try
result = method.apply(context,args)
result = fireMethod.apply(context,args)
err = result if balUtilTypes.isError(result)
catch caughtError
err = caughtError
Expand Down
Loading

0 comments on commit a303d0b

Please sign in to comment.