Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion about differentiating between Socket, Http and possibly Cache entities

See original GitHub issue


There has been some discussion before about inconsistencies in entities received by either the WebSocket, HTTP requests or from the cache. This issue has come up in several issues before (#583, #582, #472). Other issues that are partially related would be (#435, #571). Opening this issue for centralized further discussion.


I personally think it would be best to create abstract classes for entities that contain fields that are always available. For Socket and HTTP we’d implement these abstract classes with the additional fields these channels provide. We could also provide a separate Cache entity for everything that gets cached, but I’m not 100% sure whether that’s a good idea (yet).

Some pseudocode on what I’d assume it to look like

DiscordSocketGuild guild = e.Guild; // A guild received by the websocket, e.g. in an event handler.
DiscordHttpGuild guild2 = await client.GetGuildAsync(379378609942560770); // A guild received from HTTP
BaseDiscordGuild guild3 = guild; // DiscordSocketGuild implements BaseDiscordGuild so we can assign it to that type
guild3 = guild2; // So can we for the HTTP guild

After assigning our guild to BaseDiscordGuild, we’d assure that all fields on that type are available.

Of course, my word is not final. Please discuss on other viable solutions, or improve on what I proposed. (yes, I’m technically a main maintainer but for this project it’s more important to do what the community wishes)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

VelvetToroyashicommented, Apr 13, 2021

What I mean is more akin to: IEntityWhatever as the abstract base for anything that is an EntityWhatever (say, guild), and then you have GatewayEntityWhatever and RestEntityWhatever, the 2 of which the users don’t know about, they only deal with the IEntityWhatever type. This complicates dealing with differences between gateway and REST a little, but avoids the “oh no as ConcreteType1 didn’t work because it’s as ConcreteType2 ur lib is shit fix nao”

Just chiming in regarding this; while I do agree that abstraction is a double-sided coin with lots of pros and cons, when it comes to responsibility and accountability for abstraction, I feel the liability of dealing with egregious issues that simply state “lib no work plz fix” is not ours; if we provide abstractions, it’s up to the end user to be competent enough to realize what an abstraction even is, especially in the case of realizing something is an interface and trying to cast to a concrete type, but that’s just my two cents.

Look forward to seeing where this decision goes, as I’ve whined about abstraction before, and currently resorting to my own, but even the most basic interfaces would be much appreciated. ❤️

Emzi0767commented, Apr 13, 2021

One thing I don’t think should happen, because it was a mistake dnet made, was allowing direct access to underlying type. Guarantees should be made about what the object contains and can do, but not about what it is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSockets protocol vs HTTP
1) Why is the WebSockets protocol better? WebSockets is better for situations that involve low-latency communication especially for low ...
Read more >
HTTP & WebSockets
WebSocket is a communication protocol that allows clients(like browsers) and servers to communicate on a full-duplex channel over a long time ...
Read more >
What is web socket and how it is different from the HTTP?
WebSocket: WebSocket is bidirectional, a full-duplex protocol that is used in the same scenario of client-server communication, unlike HTTP it ...
Read more >
Web Socket vs HTTP: What to choose for your next API ...
In this article we will learn more about Web Socket and HTTPS, which is best suited, difference between the two and limitations and...
Read more >
WebSockets vs HTTP: Which to choose for your project
An overview of the HTTP and WebSocket protocols, including their pros and cons, and the best use cases for each protocol.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found