Skip to content

Commit

Permalink
Fixed test, but now Task is a promise
Browse files Browse the repository at this point in the history
  • Loading branch information
thejmazz committed Jun 29, 2016
1 parent 8325dee commit 3376167
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
16 changes: 12 additions & 4 deletions lib/Task.js
Expand Up @@ -74,8 +74,15 @@ class ReadableFromCallback extends stream.Readable {
* @param {function} actionCreator function to produce an actionCreator
* @return {stream} stream to be orchestrated
*/
const task = (props, actionCreator) => () => co.wrap(function * () {
const task = (props, actionCreator) => co.wrap(function * () {
// TODO check if actionCreator is a function
if (props === null) {
console.log('Got null props')
props = {
input: null,
name: 'noname'
}
}


// TODO handle unnamed task
Expand All @@ -96,8 +103,8 @@ const task = (props, actionCreator) => () => co.wrap(function * () {
} catch(e) {
console.error(e)
}
console.log(tab(2) + 'input: ' + resolvedInput.input + ' from ' + input.value)
}
console.log(tab(2) + 'input: ' + resolvedInput.input + ' from ' + input.value)
// 3. creating
// TODO use input/output, resolved promise, callback to determine stream type.
// Or just always be duplex.
Expand All @@ -107,6 +114,7 @@ const task = (props, actionCreator) => () => co.wrap(function * () {
// Create the action
// TODO handle actual callbacks, in which case we cant call this yet
const resolvedProps = Object.assign(props, resolvedInput)
console.log(resolvedProps)
const action = actionCreator(resolvedProps)

// Get its type: can be stream, promise, function
Expand Down Expand Up @@ -143,9 +151,9 @@ const task = (props, actionCreator) => () => co.wrap(function * () {
// 5. resolving output
// 6. ending, passing on output

console.log(stream)
// console.log(stream)

return stream
})()
})

module.exports = task
15 changes: 9 additions & 6 deletions test/Task.spec.js
Expand Up @@ -22,14 +22,17 @@ describe('Task', function() {
describe('when provided with a Promise', function() {
describe('that resolves to a value', function() {
it('should return a readable stream', function(done) {
const task = Task(null, () => new Promise((resolve, reject) => resolve('datums')))()
Task(null, () => new Promise((resolve, reject) => resolve('datums')))().then((task) => {
console.log('task: ' + task)

assert.isOk(isReadable(task))
assert.isNotOk(isWritable(task))
assert.isOk(isReadable(task))
assert.isNotOk(isWritable(task))

task
.on('data', noop)
.on('end', () => done())
task
.on('data', noop)
.on('end', () => done())
})

})
})
})
Expand Down

0 comments on commit 3376167

Please sign in to comment.