Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #33018

synchronizing asynchronus request

From Une Bévue <unbewusst.sein@fai.invalid>
Newsgroups comp.lang.javascript
Subject synchronizing asynchronus request
Date 2017-04-16 08:30 +0200
Organization Posted through ALPHANET (http://www.alphanet.ch/)
Message-ID <ocv32h$248$1@shakotay.alphanet.ch> (permalink)

Show all headers | View raw


I've an app requesting different values to a websocket server :
albums ;
cameras ;
locations ;
persons ...
  ...

Then i have answers being asynchronous, but I'd like to synchronize all 
the answers at the time of the latest.

The code is like (ES6) :

     let requestAlbums  = {database: 'photos', ...};
     this.props.socket.sendRequest(requestAlbums, (message) => {
       this.setState({albums: message.results.albums});
     });

     let requestCameras  = {database: 'photos', ...};
     this.props.socket.sendRequest(requestCameras, (message) => {
       this.setState({cameras: message.results.cameras});
     });

     let requestLocations  = {database: 'photos', ...};
     this.props.socket.sendRequest(requestLocations, (message) => {
       this.setState({locations: message.results.locations});
     });

     let requestPersons  = {database: 'photos', ...};
     this.props.socket.sendRequest(requestPersons, (message) => {
       this.setState({persons: message.results.persons});
     });

I'd like to "wait" for the latest result (aka "persons") in order to 
have only one this.setState like :

let albums = message.results.albums;
let cameras = message.results.cameras;
let locations = message.results.locations;
let persons = message.results.persons;

this.setState({
     albums:    albums,
     cameras:   cameras,
     locations: locations,
     persons:   persons
});

albums, cameras, locations and persons being "memorized/bufferized" 
somewhere...

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


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