Service Binding in Cloudflare Workers

You probabaly want to use a service bind to make a worker calls itself https://developers.cloudflare.com/workers/configuration/bindings/about-service-bindings/
9 Replies
Joy
Joy7mo ago
For the binding do I need to make 2 separate workers?
Cyb3r-Jak3
Cyb3r-Jak37mo ago
No, you have can service bindings for the same worker. Though it might be easier to just have your code call the same function as endpoint B
Joy
Joy7mo ago
can you share some github gist of it or even any repo
Cyb3r-Jak3
Cyb3r-Jak37mo ago
Of service binding to self?
Joy
Joy7mo ago
yes. I mean I am not sure about how can I bind a service to self. I tried finding out docs but ended up creating another worker and now it says to add variable name here.
No description
Joy
Joy7mo ago
Like I said previously these are 2 endpoints. Now when /invite gets triggered I have few ms to send back the response otherwise request would time out. That is why I've create /mention-each route. The purpose of it is to do the computing on the behalf of /invite. But this enpoint should get trigger automatically.
No description
Cyb3r-Jak3
Cyb3r-Jak37mo ago
I’d recommend responding to the original reaction and using ctx.waitUntil to do the rest of the work. Also means your worker will only have to do one request.
Joy
Joy7mo ago
Hello @Cyb3r-Jok3 just wanted you to know that I am now calling the endpoint like this, using waitUntil. The error which I was getting earlier was because of quickly closing a connection. But using watUntil solved the problem.
No description
Joy
Joy7mo ago
Update : instead of making another API call. I've provided the promised version of my actual logic and it is working absolutely fine. Thanks a lot for helping me out. @Cyb3r-Jok3
Want results from more Discord servers?
Add your server