fcall/fapply difficulties

76 views
Skip to first unread message

Kiran Sonnad

unread,
Aug 20, 2013, 1:48:29 PM8/20/13
to q-con...@googlegroups.com
Having trouble understanding exactly how to use fcall and fapply in this situation:

1  return promiseReturningFunction()
2  .then(anotherPromiseReturningFunction)
3  .then(function() { return promiseReturningFunctionWithArgs(arg1, arg2); })
4  .then(doSomeStuffFunction)
5  .fail(doFailureStuffFunction);

For brevity and clarity, I'd like to transform line 3 into

3  .fcall(promiseReturningFunctionWithArgs, arg1, arg2)

or

3.  fapply(promiseReturningFunctionWithArgs, [arg1, arg2])

But changing that line causes TypeError failures.  Am I misusing these?

Kris Kowal

unread,
Aug 20, 2013, 1:55:11 PM8/20/13
to Q Continuum
Yes, fcall and fapply are for calling function a promise resolves to, or in the common case, for calling a function such that the result is guaranteed to be a wrapped in a promise.

Examples:

Q.fcall(function () {
});

Q(function (one, two, three) {
}).fcall(1, 2, 3);

We do not have an abbreviated form for your line 3.

Kris Kowal

Kiran Sonnad

unread,
Aug 20, 2013, 2:01:44 PM8/20/13
to q-con...@googlegroups.com, kris....@cixar.com
Okay. Thanks for the speedy response.
Reply all
Reply to author
Forward
0 new messages