Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: cancelInline is not a function #62

Closed
KubaVejrazka opened this issue Dec 13, 2024 · 2 comments
Closed

TypeError: cancelInline is not a function #62

KubaVejrazka opened this issue Dec 13, 2024 · 2 comments
Labels
seen I've seen and read this issue and I'll try find some time soon to work on it.

Comments

@KubaVejrazka
Copy link

Problem

I believe the library tried to call a non-existant function.

Code snippet

import { env } from '$env/dynamic/private';
import { fail, type RequestEvent } from '@sveltejs/kit';
import { produce } from 'sveltekit-sse';

// ---------- not important in regards to the problem, just for context ----------
function delay(milliseconds: number) {
  return new Promise(function run(resolve) {
    setTimeout(resolve, milliseconds);
  });
}

async function getImg() {
  try {
    const url = env.IMAGE_URL;
    const response = await fetch(url as string);
    const json = await response.json();
    if (json.image) return json.image;
  } catch (err) {
    return null;
  }
}

async function testImgAcessibility() {
  const img = await getImg();
  if (img) return true;
  return false;
}

export async function POST(event: RequestEvent) {
  if (!event.locals.session) {
    return fail(400);
  }
  const imgAcessible = await testImgAcessibility();
  console.log('able to fetch image:', imgAcessible);
// ---------- ---------- the important part ---------- ----------
  return produce(
    async function start({ emit }) {
      console.log(
        'started streaming to:',
        event.locals.user!.type,
        '(session id: ' + event.locals.session!.id + ')'
      );
      while (true) {
        const img = await getImg();
        if (img) {
          const { error } = emit('message', img);
          if (error) {
            console.log('error in emit:', error);
            return;
          }
          await delay(16);
        } else {
          const { error } = emit('error', 'nullimg');
          if (error) {
            console.log('error in emit:', error);
            return;
          }
          await delay(1000);
        }
      }
    },
    {
      stop() {
        console.log('stopped streaming to:', event.locals.user!.type);
      }
    }
  );
}

Error

started streaming to: student (session id: yt7ea335sffwpiwkxvt4stuyamftibpoc35dhrp3)
/home/kuba/Documents/Code/hackathon/node_modules/sveltekit-sse/dist/produce.js:105
          await cancelInline(self)
                ^

TypeError: cancelInline is not a function
    at stopLocal (/home/kuba/Documents/Code/hackathon/node_modules/sveltekit-sse/dist/produce.js:105:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Array.run (/home/kuba/Documents/Code/hackathon/node_modules/sveltekit-sse/dist/produce.js:112:13)

Node.js v22.11.0
@razshare razshare added the seen I've seen and read this issue and I'll try find some time soon to work on it. label Dec 13, 2024
razshare referenced this issue Dec 13, 2024
…ancelInline when it was not an actual function.
@razshare
Copy link
Owner

Hello @KubaVejrazka , thanks for the issue!

I can't seem to reproduce it though but I think I figured what the problem was and fixed it.

Please update to version v0.13.11 and let me know if this fixed your issue.

@razshare
Copy link
Owner

Closing this for inactivity, feel free to open a separate issue if it persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
seen I've seen and read this issue and I'll try find some time soon to work on it.
Projects
None yet
Development

No branches or pull requests

2 participants