Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2013-05-25 Thread Jean Hugues Robert
Le jeudi 23 mai 2013 19:32:25 UTC+2, Domenic Denicola a écrit : That's overstating it a bit. It's very easy to convert to promise-based code, e.g.: var fs = require('fs'); var Q = require('q'); var readFile = Q.denodeify(fs.readFile); var writeFile = Q.denodeify(fs.writeFile);

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2013-05-23 Thread Baz
Using callbacks in your own application code is the path of least resistance for using the majority of value in the node ecosystem. I am new to Node and trying to decide between promises, asynch and vanilla, there are so many good arguments for each. Mikeal, do you mind expanding further

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2013-05-23 Thread Matt
On Thu, May 23, 2013 at 3:29 AM, Baz b...@thinkloop.com wrote: I am new to Node and trying to decide between promises, asynch and vanilla, there are so many good arguments for each. Mikeal, do you mind expanding further how using promises in your own, non-shared, code could hinder use of

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2013-05-23 Thread Baz
Thanks Matt, so just to be crystal clear, if I'm using promises in my own code, then I happen to have a flow that depends on fs, for example, and since fs doesn't return or use promises, I would have to drop out of the promises paradigm and manage that particular part of the flow control with

RE: [nodejs] Re: trying to wrap my head around promises - async vs Q

2013-05-23 Thread Domenic Denicola
23, 2013 13:28 To: nodejs@googlegroups.com Subject: Re: [nodejs] Re: trying to wrap my head around promises - async vs Q Thanks Matt, so just to be crystal clear, if I'm using promises in my own code, then I happen to have a flow that depends on fs, for example, and since fs doesn't return or use

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2013-05-23 Thread // ravi
On May 23, 2013, at 1:28 PM, Baz b...@thinkloop.com wrote: Thanks Matt, so just to be crystal clear, if I'm using promises in my own code, then I happen to have a flow that depends on fs, for example, and since fs doesn't return or use promises, I would have to drop out of the promises

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2013-05-23 Thread Baz
Thank you gents, perfectly got it now. On Thu, May 23, 2013 at 10:42 AM, // ravi ravi-li...@g8o.net wrote: On May 23, 2013, at 1:28 PM, Baz b...@thinkloop.com wrote: Thanks Matt, so just to be crystal clear, if I'm using promises in my own code, then I happen to have a flow that depends on

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-13 Thread greelgorke
it's not backwards. first function is on top, last at the bottom, functions, which may appear multiple times in the callback chain are at the top most position by convention. i use the function declaration statement for this, because they get hoisted and the definition order is irrelevant

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread greelgorke
my approach to handle callback sallad? use the language features. just wrote down a script that would have a 7-10 callbacks nested. The problem with the callbacks is not the callback approach. it's simple and beautiful. the problem is naive and blind utilization of the closure scope. Just an

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread Mariusz Nowak
If I would choose which tool is best for my project just by popularity factor I wouldn't go far. It's understood that Async is more popular as it doesn't introduce much learning factor and most developers are looking for quick solutions. To get promises you need to devote a while understand

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread Bradley Meck
Choose either, I do things in callback style personally to match the ecosystem when I write libraries, thats the expectation of the ecosystem. For application logic, do whatever makes it faster. There are exactly 0 absolute wins on either side. I can go on at length about the reason both have

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread Nuno Job
If I would choose which tool is best for my project just by popularity factor I wouldn't go far. I have a way to solve this issue that emulates pattern matching in javascript `github/dscape/p` while maintaing valid JS semantics. Its so unpopular even I dont use it :) (but it works I

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread Andy
One of them problems even with this approach is that you write and read code backwards. It executes bottom to top because you have to define named callback functions first. I find it much more natural with promises because not only is your code organized, but it reads top to bottom and is MUCH

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread Andy
On Sunday, November 11, 2012 10:46:05 PM UTC-8, Mikeal Rogers wrote: Some people clearly like promises, but the dominant pattern in node is not promises, it's callbacks, with complex callback issues managed with async. Stating your opinion strongly does not make it a fact. This is your

RE: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread Domenic Denicola
reasons as the first parameter (i.e. as an error). This allows you to create libraries that expose both promise-returning and callback-accepting APIs at the same time. From: Andy Sent: November 12, 2012 17:52 To: nodejs@googlegroups.com Subject: Re: [nodejs] Re: trying to wrap my head around

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread Matt
On Mon, Nov 12, 2012 at 5:48 PM, Andy delvarwo...@gmail.com wrote: One of them problems even with this approach is that you write and read code backwards. It executes bottom to top because you have to define named callback functions first. I find it much more natural with promises because not

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread Mark Hahn
because you have to define named callback functions first. No you don't. I always name then in order ... func1 = - do something; func2() func2 = - do something; func3() func3 = - do something func1() On Mon, Nov 12, 2012 at 2:48 PM, Andy delvarwo...@gmail.com wrote: One of them problems

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread Andy
In JavaScript the order you define things doesn't matter. It does if your function declaration style is var funcName = function() { }; which is the style I use. Personal preference obviously. -- Job Board: http://jobs.nodejs.org/ Posting guidelines:

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread Mark Hahn
Read the message before this. I explained how it works in a forward way with your preferred method of function definition. That is what I always use. On Mon, Nov 12, 2012 at 3:46 PM, Andy delvarwo...@gmail.com wrote: In JavaScript the order you define things doesn't matter. It does if

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-12 Thread Mark Hahn
P.S. Coffeescript only supports that way of defining a function. On Mon, Nov 12, 2012 at 3:51 PM, Mark Hahn m...@hahnca.com wrote: Read the message before this. I explained how it works in a forward way with your preferred method of function definition. That is what I always use. On

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-11-11 Thread Mikeal Rogers
It's great that you have a strong opinion. Here's some numbers: Here's the number of modules that depend on async and Q. async: 975 Q: 109 Here are the numbers of downloads in the last month. async: 120,271 Q: 33,242 Some people clearly like promises, but the dominant pattern in node is not

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-07-03 Thread Bruno Jouhier
Hi José Transforming *every* construct of Javascript is exactly what streamline.js does. Here is a typical piece of code: function mongoSearch(_, q) { var t0 = new Date(); var db = new mongodb.Db('tutorial', new mongodb.Server(127.0.0.1, 27017, {})); db.open(_); try {

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-07-02 Thread Alan Gutierrez
On Sun, Jul 01, 2012 at 04:04:12PM -0700, Alexey Petrushin wrote: There are some good use cases for control flow libraries, but, sadly, in most cases the end result is even worse than without it. It seems there's no good solution to this problem - code looks ugly no matter what You do -

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-07-01 Thread Mark Miller
On Sun, Jul 1, 2012 at 3:08 PM, Ken Whitesell kenwhites...@comcast.netwrote: On Sunday, July 1, 2012 2:55:05 PM UTC-4, Mariusz Nowak wrote: n promises approach asynchronous state is represented with the object, so instead of registering single callback, you get the object, which you can pass

Re: [nodejs] Re: trying to wrap my head around promises - async vs Q

2012-07-01 Thread Mark Miller
Thanks Domenic, this is indeed an excellent presentation. I especially like your emphasis on getting the exception propagation right. It's something I should emphasize more as well. On Sun, Jul 1, 2012 at 3:43 PM, Domenic Denicola dome...@domenicdenicola.com wrote: I'd like to submit my