I have asked myself this question several times before:
Is it possible to have a JavaScript function used multiple times from multiple locations returning a promise calling
ctx.executeQueryAsync
, but only doing a single request to server from browser?
This is not the same as just wrapping executeQueryAsync
in a promise, as that would possibly result in multiple requests to server.
It is also the opposite of a normal Q.all
-function which waits for several promises to finish. Instead I want to wait for one single promise to finish then call out to a random amount of "listeners".
The reason I post an answer to my own question is because I haven't seen it come up before, and I find it really neat and a nice-to have solution which I want to share.