Coder Social home page Coder Social logo

Async issues with API calls about esl HOT 4 CLOSED

shimaore avatar shimaore commented on August 21, 2024
Async issues with API calls

from esl.

Comments (4)

grEvenX avatar grEvenX commented on August 21, 2024

Tested out the lastest in master-branch utilizing Q/promises which has a similar issue. In this case however the correct callback is called in time, just with the wrong result in one of the cases.

In this case the result of the operation is

Callback1: 1325376000
Callback2: 1325376000

The code I used following the example in the Readme.md is:

(function () {
   'use strict';

    var esl = require('./esl/lib/esl');

    esl.client( function (eslResponse) {
        console.log("...Connected to FS");

        eslResponse.sequence([
            function () {
                this.api('strepoch 2013-01-01').then(function(apiResponse) {
                    console.log("Callback1: " + apiResponse.body);
                    return Q(true);
                });
            }, function () {
                return this.api('strepoch 2012-01-01').then(function(apiResponse2) {
                    console.log("Callback2: " + apiResponse2.body);
                    return Q(true);
                });
            }
        ]);
    }).connect(8021, '127.0.0.1');
}());

The full output when running this is:

27 Jun 07:17:05 - { when: 'connection listener emit freeswitch_connect',
  call: 
   { socket: 
      { _events: [Object],
        _connecting: false,
        _handle: [Object],
        _readableState: [Object],
        readable: true,
        domain: null,
        _maxListeners: 10,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: false,
        onend: null,
        destroyed: false,
        errorEmitted: false,
        bytesRead: 0,
        _bytesDispatched: 0,
        _pendingData: null,
        _pendingEncoding: '',
        pipe: [Function],
        addListener: [Function],
        on: [Function],
        pause: [Function],
        resume: [Function],
        read: [Function],
        _consuming: true } } }
27 Jun 07:17:05 - { headers: { 'Content-Type': 'auth/request' }, body: undefined }
27 Jun 07:17:05 - { when: 'connection listener socket.emit',
  event: 'freeswitch_auth_request',
  call: 
   { socket: 
      { _events: [Object],
        _connecting: false,
        _handle: [Object],
        _readableState: [Object],
        readable: true,
        domain: null,
        _maxListeners: 10,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: false,
        onend: null,
        destroyed: false,
        errorEmitted: false,
        bytesRead: 28,
        _bytesDispatched: 0,
        _pendingData: null,
        _pendingEncoding: '',
        pipe: [Function],
        addListener: [Function],
        on: [Function],
        pause: [Function],
        resume: [Function],
        read: [Function],
        _consuming: true },
     headers: { 'Content-Type': 'auth/request' },
     body: undefined } }
27 Jun 07:17:05 - { when: 'Challenged for authentication' }
27 Jun 07:17:05 - { headers: 
   { 'Content-Type': 'command/reply',
     'Reply-Text': '+OK accepted' },
  body: undefined }
27 Jun 07:17:05 - { when: 'connection listener socket.emit',
  event: 'freeswitch_command_reply',
  call: 
   { socket: 
      { _events: [Object],
        _connecting: false,
        _handle: [Object],
        _readableState: [Object],
        readable: true,
        domain: null,
        _maxListeners: 10,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: false,
        onend: null,
        destroyed: false,
        errorEmitted: false,
        bytesRead: 82,
        _bytesDispatched: 14,
        _pendingData: null,
        _pendingEncoding: '',
        pipe: [Function],
        addListener: [Function],
        on: [Function],
        pause: [Function],
        resume: [Function],
        read: [Function],
        _consuming: true },
     headers: 
      { 'Content-Type': 'command/reply',
        'Reply-Text': '+OK accepted' },
     body: undefined } }
27 Jun 07:17:05 - { when: 'Authentication sent',
  call: 
   { socket: 
      { _events: [Object],
        _connecting: false,
        _handle: [Object],
        _readableState: [Object],
        readable: true,
        domain: null,
        _maxListeners: 10,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: false,
        onend: null,
        destroyed: false,
        errorEmitted: false,
        bytesRead: 82,
        _bytesDispatched: 14,
        _pendingData: null,
        _pendingEncoding: '',
        pipe: [Function],
        addListener: [Function],
        on: [Function],
        pause: [Function],
        resume: [Function],
        read: [Function],
        _consuming: true },
     headers: 
      { 'Content-Type': 'command/reply',
        'Reply-Text': '+OK accepted' },
     body: undefined } }
...Connected to FS
27 Jun 07:17:05 - { headers: { 'Content-Type': 'api/response', 'Content-Length': '10' },
  body: '1356998400' }
27 Jun 07:17:05 - { when: 'connection listener socket.emit',
  event: 'freeswitch_api_response',
  call: 
   { socket: 
      { _events: [Object],
        _connecting: false,
        _handle: [Object],
        _readableState: [Object],
        readable: true,
        domain: null,
        _maxListeners: 10,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: false,
        onend: null,
        destroyed: false,
        errorEmitted: false,
        bytesRead: 196,
        _bytesDispatched: 64,
        _pendingData: null,
        _pendingEncoding: '',
        pipe: [Function],
        addListener: [Function],
        on: [Function],
        pause: [Function],
        resume: [Function],
        read: [Function],
        _consuming: true },
     headers: { 'Content-Type': 'api/response', 'Content-Length': '10' },
     body: '1356998400' } }
27 Jun 07:17:05 - { headers: { 'Content-Type': 'api/response', 'Content-Length': '10' },
  body: '1325376000' }
27 Jun 07:17:05 - { when: 'connection listener socket.emit',
  event: 'freeswitch_api_response',
  call: 
   { socket: 
      { _events: [Object],
        _connecting: false,
        _handle: [Object],
        _readableState: [Object],
        readable: true,
        domain: null,
        _maxListeners: 10,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: false,
        onend: null,
        destroyed: false,
        errorEmitted: false,
        bytesRead: 196,
        _bytesDispatched: 64,
        _pendingData: null,
        _pendingEncoding: '',
        pipe: [Function],
        addListener: [Function],
        on: [Function],
        pause: [Function],
        resume: [Function],
        read: [Function],
        _consuming: true },
     headers: { 'Content-Type': 'api/response', 'Content-Length': '10' },
     body: '1325376000' } }
Callback1: 1325376000
Callback2: 1325376000

from esl.

shimaore avatar shimaore commented on August 21, 2024

(Sorry for the delay, just came back from vacation.)

In the 0.3.2 test you would have to send the request sequentially by calling eslResponse.api('conference list'..) from within the callback of the first call to eslResponse.api.

In the 1.0 version .sequence should do it for you, but I suspect it gets confused by return Q(true). I think return (or simply omitting the return statement) should do the trick. Edit: it doesn't, see below for the solution.

from esl.

shimaore avatar shimaore commented on August 21, 2024

In 1.0 the proper way to do it is:

(function () {
    var esl = require('./esl/lib/esl');

    esl.client( function (eslResponse) {
        console.log("...Connected to FS");

        eslResponse.sequence([
            function () {
                return this.api('strepoch 2013-01-01');
            }
          , function() {
                console.log("Callback1: " + this.body);
            }
          , function () {
                return this.api('strepoch 2012-01-01');
            }
          , function() {
                console.log("Callback2: " + this.body);
            }
        ]);
    }).connect(8021, '127.0.0.1');
}());

from esl.

shimaore avatar shimaore commented on August 21, 2024

Obsoleted in 2.x. The proper way to do it would now look like:

    @api 'sofia status'
    .then (res) ->
      console.log res.body
      @api 'conference list'
    .then (res) ->
      console.log res.body

from esl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.