Has anyone had issues with subscriptions not firin...
# orm-help
r
Has anyone had issues with subscriptions not firing? I'm using them to trigger welcome emails for users, but inconsistently don't always fire.
h
Are you talking about subscriptions in prisma.yml?
r
No, using
await prisma.$subscribe
h
oh okay, might be related to https://github.com/prisma/prisma/issues/3950 Any reason why are you not firing the email just after creating the user in the createUser mutation
r
@Harshit I figured that subscriptions were a nice decoupled way of handling it (assumed I could change the user's state in other ways - unsure how as yet - and the subscription would handle it)
If it were that bug (the github issue) wouldn't the await return with
done: true
?
(turning on browser notifications - I keep missing your replies!)
h
Can you please share some code?
r
sure - one sec
@Harshit sorry - multiple slack windows! https://gist.github.com/remy/f6969fbfcfc95948d4310498bfd51ab4 - the
if (done)
never actually logs for me.
So it seems like the
$subscription
is still going, but perhaps the websocket has been dropped?
h
Looks like the while loop might be causing this, you should use for...await here
Copy code
for await (let data of createUserIterator) {
     // do stuff here
    const { done, value: user } = data;
   }
r
In theory that's the same code
Except I don't need to transpile to get support for it
h
I don't think you need to transpile it and I have got into trouble with while loop as it is infinite loop
it can cause potential leaks
r
hmm. I've got a feeling that when I ran it with Jest it complained that it couldn't run that code.
h
I think these are not equivalent. Also, this is supported in node v10
please check you node version, I think you should use node v10 as it the latest LTS
r
Yep - using 10
(damn notifications aren't working in this slack window - sorry for delayed replies!)
Yea, 10.14.1
I'll double check jest
huh, jest is working. I really can't remember what it was that was complaining about that syntax, but I'll keep using it for now.
(the syntax you suggested). If the socket is dropped, will it have
done: true
?
h
yes, it is based on the next value
this is the proper way to do a iteration over an async iterable