Turning a condition into a promise resolution/rejection

40 views
Skip to first unread message

// ravi

unread,
Apr 13, 2014, 6:12:13 PM4/13/14
to q-con...@googlegroups.com

Hello all,

I recall reading an issue reported on GitHub a while ago on this, but I unfortunately cannot find it. I am wondering if there is a more elegant way to do this:

Q.fcall(assert, files.length === 1).then(copy_files).fail(report_bad_file_count).done()

Regards,

—ravi


P.S: The GitHub page says: "You can create a promise from a value using Q.fcall.”. I wonder if it would be clearer if it said “You can create a promise from a return value using Q.fcall”.

Domenic Denicola

unread,
Apr 13, 2014, 8:06:31 PM4/13/14
to q-con...@googlegroups.com

I think the most elegant way to do this would be

 

(files.length === 1 ? copy_files() : report_bad_file_count()).done();

 

since it uses standard language constructs instead of trying to make Q do the work.

--
You received this message because you are subscribed to the Google Groups "Q Continuum (JavaScript)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to q-continuum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

// ravi

unread,
Apr 13, 2014, 8:17:56 PM4/13/14
to q-con...@googlegroups.com
On Apr 13, 2014, at 8:06 PM, Domenic Denicola <dom...@domenicdenicola.com> wrote:
I think the most elegant way to do this would be
 
(files.length === 1 ? copy_files() : report_bad_file_count()).done();
 
since it uses standard language constructs instead of trying to make Q do the work.
 

Fair enough!

—ravi
Reply all
Reply to author
Forward
0 new messages