Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #33043
| From | Une Bévue <unbewusst.sein@fai.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Solved: synchronizing asynchronus request |
| Date | 2017-04-18 11:58 +0200 |
| Organization | Posted through ALPHANET (http://www.alphanet.ch/) |
| Message-ID | <od4o09$og4$1@shakotay.alphanet.ch> (permalink) |
| References | <ocv32h$248$1@shakotay.alphanet.ch> <od3fqe$1bi1$1@gioia.aioe.org> |
Le 18/04/2017 à 00:32, Richard Maher a écrit :
>>
> Could Promises help you here?
>
> https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
>
Yes, u'r right !
I did it in the mean time [test in ES5]:
var promises = [];
var albumsPromise = new Promise(function(resolve, reject){
var albumsRequest = {database: 'photos', collection: 'albums', mode:
'read', sort: {startdate: 1, stopdate: 1}};
socketService.sendRequest(albumsRequest, function (message) {
resolve({
albums_delay: ((new Date()).getTime() - start),
albums_count: message.results.albums.length, albums:
message.results.albums
});
});
});
promises.push(albumsPromise);
the like for cameras, locations, person etc.
and then :
Promise.all(promises).then(function(datas) {
here I have an Array of object, then i re-arrange to a sole object by :
var data = {promises_count: promises.length};
for (var i = 0, l = datas.length; i < l; i++) {
for (var prop in datas[i]) {
data[prop] = datas[i][prop];
}
}
});
here (ie; with Promise.all) the delay is roughly the longest delay.
I have tested another solution like :
var albumsTrick = function () { return new Promise(blahblahblah);};
and then : albumsTrick.then(camerasTrick)...
in that case, if n is the number of socket requests, the time delay is
at least n * (a delay roughly 50 ms)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
synchronizing asynchronus request Une Bévue <unbewusst.sein@fai.invalid> - 2017-04-16 08:30 +0200
Re: synchronizing asynchronus request Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-16 11:09 +0100
Re: synchronizing asynchronus request Une Bévue <unbewusst.sein@fai.invalid> - 2017-04-16 18:38 +0200
Re: synchronizing asynchronus request Richard Maher <maher_rjSPAMLESS@hotmail.com> - 2017-04-18 06:32 +0800
Solved: synchronizing asynchronus request Une Bévue <unbewusst.sein@fai.invalid> - 2017-04-18 11:58 +0200
Re: Solved: synchronizing asynchronus request Richard Maher <maher_rjSPAMLESS@hotmail.com> - 2017-04-18 21:39 +0800
Re: Solved: synchronizing asynchronus request Une Bévue <unbewusst.sein@fai.invalid> - 2017-04-19 07:10 +0200
Re: Solved: synchronizing asynchronus request "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-19 12:17 +0200
csiph-web