Git Product home page Git Product logo

Comments (6)

miralemd avatar miralemd commented on June 1, 2024

hmm, you're using async/promise which I haven't tried at all. It could be a race condition where the end is called and stream closed before your promises have resolved. Try moving the line https://github.com/miralemd/qlik-sse/blob/master/lib/index.js#L29 last into your own function, or test write without any use of async await.

from qlik-sse.

RobWunderlich avatar RobWunderlich commented on June 1, 2024

As @miralemd suggested, when using await the request.end() will get called too early. I resolved the issue for myself by adding an async property to the function config that drives a conditional request.end(). https://github.com/RobWunderlich/qlik-sse/commit/be4bc04ab3ca655bed5f9a2f0c76d5ee054d87eb
@miralemd do you want to accept a PR for this? Or is this too specialized?

from qlik-sse.

miralemd avatar miralemd commented on June 1, 2024

fixed by 233e014

from qlik-sse.

rileymd88 avatar rileymd88 commented on June 1, 2024

@RobWunderlich & @miralemd Thanks for the update. My code still does not seem to want to handle using async. Here is a super easy example which still has request.end() calling too early. Any ideas?

function Test(request) {
  function waitUntil(i) {
    return new Promise(function(resolve, reject){
        setTimeout(() => {
          resolve(i);
        }, 500);
    });
  }
  request.on('data', async function (bundle) {
    console.log('data');
    let list = [];
    for(let i = 0; i < 10; i++) {
       console.log(i);
       let resp = await waitUntil(i);
       list.push(resp);
    }
    console.log('writing...');
    request.write({ "rows": [{ "duals": [{ "strData": list.toString() }] }] });
  });
}

from qlik-sse.

RobWunderlich avatar RobWunderlich commented on June 1, 2024

@rileymd88 The async detection expects your primary function to be marked async. So make it "async function Test(request)"

from qlik-sse.

rileymd88 avatar rileymd88 commented on June 1, 2024

@RobWunderlich Ahh ok that worked! I had to also adjust my code at the end and write request.end() after request.write(...)

from qlik-sse.

Related Issues (4)

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.