wonderful... thank you.

and in q, what would that look like?

Regards,
Reza


On Mon, Oct 21, 2013 at 1:09 PM, Mariusz Nowak <[email protected]> wrote:

> var promisify = require('deferred').promisify;
> var myAsyncFunctionPromiseVersion = promisify(myAsyncFunction);
>
> myAsyncFunctionPromiseVersion().then(function () { console.log("it
> works!"); });
>
> On 21 paź 2013, at 21:57, Reza Razavipour <[email protected]>
> wrote:
>
> Let us use an example:
>
>
>
> var q = require('q');
>
>     var myAsyncFunction = function(err, result) {
>
>     if (err)
>
>      console.log("We got an error");
>
>
>
>     console.log("Success");
>
>     };
>
>     myAsyncFunction().then(function () { console.log("promise is working");
> });
>
>
> myAsyncFunction().then(function () { console.log("it really worked"); });
>
>                       ^
>
> TypeError: Cannot call method 'then' of undefined
>
>
> How do I turn myAsyncFunction into a promise?
>
>
>
> On Monday, October 21, 2013 10:58:34 AM UTC-7, Mariusz Nowak wrote:
>>
>>
>> On 21 paź 2013, at 19:52, Reza Razavipour <[email protected]> wrote:
>>
>> we all of this I still can not figure out how to take an async function
>> and change it from callback to a promise.
>>
>>
>>
>> Many libraries provide it's own utils for that, just check their
>> documentation:
>>
>> https://github.com/kriskowal/**q#adapting-node<https://github.com/kriskowal/q#adapting-node>
>> https://github.com/medikoo/**deferred#promisify---working-**
>> with-asynchronous-functions-**as-we-know-them-from-nodejs<https://github.com/medikoo/deferred#promisify---working-with-asynchronous-functions-as-we-know-them-from-nodejs>
>> https://github.com/**petkaantonov/bluebird/blob/**master/API.md#**
>> promisepromisifyfunction-**nodefunction--dynamic-**receiver---function<https://github.com/petkaantonov/bluebird/blob/master/API.md#promisepromisifyfunction-nodefunction--dynamic-receiver---function>
>>
>>
>>
>> 1. Do I have to declare a promise before I can call a 'then' on it? Every
>> time I do not and call a then on an async function, I get a syntax error.
>>
>>
>>
>> On Friday, October 18, 2013 3:11:47 PM UTC-7, Reza Razavipour wrote:
>>>
>>> I am a fairly new to javaScript and node.js both.
>>>
>>> I am trying to wrap my head around promises and I am having a hard time.
>>> I am looking for a very simple tutorial/video on this topic and having
>>> little success.
>>>
>>> Is there a reference that can be recommended? A before and after code
>>> snippet can be a good starting position.
>>>
>>> Reza
>>>
>>>
>>>
>> --
>> --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines: https://github.com/joyent/**node/wiki/Mailing-List-**
>> 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
>> nodejs+un...@**googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en>
>>
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "nodejs" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/**
>> topic/nodejs/Fx_SjgkXvKU/**unsubscribe<https://groups.google.com/d/topic/nodejs/Fx_SjgkXvKU/unsubscribe>
>> .
>> To unsubscribe from this group and all its topics, send an email to
>> nodejs+un...@**googlegroups.com.
>> For more options, visit 
>> https://groups.google.com/**groups/opt_out<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 a topic in the
> Google Groups "nodejs" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/nodejs/Fx_SjgkXvKU/unsubscribe.
> To unsubscribe from this group and all its topics, 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 a topic in the
> Google Groups "nodejs" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/nodejs/Fx_SjgkXvKU/unsubscribe.
> To unsubscribe from this group and all its topics, 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.

Reply via email to