Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upConvert nodebacks to Task #96
Comments
robotlolita
added
c:Conversions
c:Data.Task
good first issue
p:Medium
ready
labels
Mar 22, 2017
robotlolita
added this to the v2.0.0 milestone
Mar 22, 2017
robotlolita
added
the
m:PRs welcome
label
Mar 22, 2017
robotlolita
added
k:Feature request
and removed
k:Enhancement
labels
Apr 2, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
rpearce
Apr 18, 2017
Contributor
@robotlolita I've just stumbled across this, but is this the sort of thing you're looking for? I wrote a little lib the other day for converting functions with callbacks to Tasks to solve a simple problem and was considering expanding upon it. It's also short enough to include here:
'use strict'
const Task = require('data.task')
function taskFromFn(fn, ctx) {
return function() {
var args = [].slice.call(arguments)
return new Task(function(reject, resolve) {
fn.apply(ctx,
args.concat(function(err, data) {
err ? reject(err) : resolve(data)
})
)
})
}
}
module.exports = taskFromFnIf so, I'd consider learning more about this library and taking a crack at a pull request!
|
@robotlolita I've just stumbled across this, but is this the sort of thing you're looking for? I wrote a little lib the other day for converting functions with callbacks to Tasks to solve a simple problem and was considering expanding upon it. It's also short enough to include here: 'use strict'
const Task = require('data.task')
function taskFromFn(fn, ctx) {
return function() {
var args = [].slice.call(arguments)
return new Task(function(reject, resolve) {
fn.apply(ctx,
args.concat(function(err, data) {
err ? reject(err) : resolve(data)
})
)
})
}
}
module.exports = taskFromFnIf so, I'd consider learning more about this library and taking a crack at a pull request! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
@rpearce pretty much, yep :) |
robotlolita commentedMar 22, 2017
Folktale should support converting Node-back style functions to Tasks.
A Nodeback function is a function that accepts a callback in Node-style, for example:
A conversion function would take that
readFilefunction and generate a new function that instead of taking a callback returns a Task object:Where this goes?
In the
data/conversionsmodule, asnodebackToTask.In the
data/taskmodule, asfromNodeback.Refer to existing
data/conversionsmodules, and thefrom*functions indata/maybeanddata/eitherto see more or less how this is done.