You can already use continuables & Function#bind with generators.
Using bind with generators feels very natural.
For example
```js
var async = require("gens")
var fs = require("fs")
var path = require("path")
function fileOrNull(uri, callback) {
fs.readFile(uri, function (err, file) {
callback(null, err ? null : file)
})
}
var findFile = async(function* (uri) {
var file = yield fileOrNull.bind(null, uri)
if (file) {
return file
}
file = yield fileOrNull.bind(null, path.join(uri, "index.js"))
if (file) {
return file
}
var pck = yield fileOrNull.bind(null, path.join(uri, "package.json"))
if (!pck || !pck.main) {
return new Error("NO SUCH FILE")
}
file = yield fileOrNull.bind(null, path.join(uri, pck.main))
if (file) {
return file
}
return new Error("NO SUCH FILE")
})
// will find ./foo or ./foo/index.js or finds by package.json main field
findFile("./foo", function (err, file) {
if (err) {
return console.log("no foo")
}
console.log("found file", file)
})
```
On Mon, Aug 5, 2013 at 8:23 AM, Christopher Probst <
[email protected]> wrote:
> Hi guys,
>
> today I read something about the upcomming es6 generator support and how
> useful they are in combination with promises (Q library for instance).
>
> The problem with node is that it provides only asynchronous functions (and
> synchronous.. pff).
> I think in order to use promised based io the node.js should support an
> additional function for each asynchronous function in the future or maybe a
> library which does this.
>
> I know that the Q library already exports functions like "Q.denodeify" so
> it's definitely not much work but it's still work.
>
> I've started with node a year ago and it is really a nice tool but I
> always hated the callbacks. They are not composable, verbose and absolutely
> ugly.
>
> What do you think about this issue ? Any chance direct support for this
> will ever be added ?
>
> Regards,
> Chris
>
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.