Skip to content

Commit

Permalink
Rename step to async.
Browse files Browse the repository at this point in the history
Closes #34.
  • Loading branch information
flatheadmill committed Feb 4, 2015
1 parent f973dd8 commit acc3c44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
18 changes: 9 additions & 9 deletions staccato.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ function Staccato (stream, opening) {
this._stream.once('error', this._catcher)
}

Staccato.prototype.ready = cadence(function (step) {
Staccato.prototype.ready = cadence(function (async) {
this._checkError()
if (!this._opened) {
step(function () {
async(function () {
this._stream.removeListener('error', this._catcher)
step(ev, this._stream).on('open').on(Error)
async(ev, this._stream).on('open').on(Error)
}, function () {
this._stream.once('error', this._catcher)
})
Expand All @@ -34,23 +34,23 @@ Staccato.prototype._checkError = function () {
}
}

Staccato.prototype.write = cadence(function (step, buffer) {
Staccato.prototype.write = cadence(function (async, buffer) {
this._checkError()
if (!this._stream.write(buffer)) { // <- does this 'error' if `true`?
step(function () {
async(function () {
this._stream.removeListener('error', this._catcher)
step(ev, this._stream).on('drain').on(Error)
async(ev, this._stream).on('drain').on(Error)
}, function () {
this._stream.once('error', this._catcher)
})
}
})

Staccato.prototype.close = cadence(function (step) {
Staccato.prototype.close = cadence(function (async) {
this._checkError() // <- would `error` be here?
step(function () {
async(function () {
this._stream.removeListener('error', this._catcher)
step(ev, this._stream).on('finish').on(Error)
async(ev, this._stream).on('finish').on(Error)
this._stream.end()
}, function () {
this._error = new Error('closed')
Expand Down
32 changes: 16 additions & 16 deletions t/staccato/write.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,52 @@ function write (chunk, encoding, callback) {
callback()
}

proof(3, cadence(function (step, assert) {
proof(3, cadence(function (async, assert) {
var mkdirp = require('mkdirp'),
Staccato = require('../..'),
staccato
var cleanup = cadence(function (step) {
var cleanup = cadence(function (async) {
var rimraf = require('rimraf')
step([function () {
rimraf(path.join(__dirname, 'tmp'), step())
async([function () {
rimraf(path.join(__dirname, 'tmp'), async())
}, function (_, error) {
if (error.code != "ENOENT") throw error
}])
})
step(function () {
cleanup(step())
async(function () {
cleanup(async())
}, function () {
mkdirp(path.join(__dirname, 'tmp'), step())
mkdirp(path.join(__dirname, 'tmp'), async())
}, function () {
staccato = new Staccato(createWritable(write), false)
assert(staccato, 'create')
staccato.ready(step())
staccato.ready(async())
}, function () {
staccato.write(new Buffer(1024), step())
staccato.write(new Buffer(1024), async())
}, function () {
staccato.close(step())
staccato.close(async())
}, function () {
var writable
staccato = new Staccato(writable = createWritable(write, 1), true)
staccato.ready(step())
staccato.ready(async())
writable.emit('open')
}, function () {
staccato.write(new Buffer(1024), step())
staccato.write(new Buffer(1024), async())
}, function () {
staccato.write(new Buffer(1024), step())
staccato.write(new Buffer(1024), async())
}, function () {
assert(1, 'opened and drained')
staccato.close(step())
staccato.close(async())
}, [function () {
var writable
staccato = new Staccato(writable = createWritable(write, 1), true)
writable.emit('error', new Error('foo'))
staccato.ready(step())
staccato.ready(async())
}, function (_, error) {
assert(error.message, 'foo', 'error caught')
}], function () {
if (!('UNTIDY' in process.env)) {
cleanup(step())
cleanup(async())
}
})
}))

0 comments on commit acc3c44

Please sign in to comment.