jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
<hightower2>
<hightower2> If a class includes Mod1, then asking Mod1 === (instance) will return true.
<hightower2> But type of that instance won't be Mod1 of course, as it's not a subclass.
<hightower2> or rather, let me try a carc example
<FromGitter> <Blacksmoke16> instead of `A.class`, do `M`
<FromGitter> <Blacksmoke16> but would have to `extend M` not include it
<hightower2> aha ok
<hightower2> hm in macros, if I have argument String.class , how get from that to having String ?
<FromGitter> <Blacksmoke16> `.gsub /\.class/, ""`
<FromGitter> <Blacksmoke16> but to be clear, those arent the same thing
<hightower2> yes, right, I would need to change the type, not do the string substitution
<FromGitter> <Blacksmoke16> what are you trying to do exactly?
<hightower2> Playing with code where I changed SomeClass.all_subclasses into SomeModule.includers . So now the arguments I get are different (where previously I'd get "SomeSubclass" from a call to all_subclasses, now with .includers I get SomeSubclass.class
<FromGitter> <Blacksmoke16> mm you should get the same thing
<hightower2> tested, with .all_includers, I get elements like SubClass1, SubClass2, etc. While with .includers I get SubClass.class
<FromGitter> <Blacksmoke16> example?
<hightower2> let me try on carc
<hightower2> ouch, indeed
<hightower2> not sure wth then
<FromGitter> <Blacksmoke16> mhm
<hightower2> I mean I do: {% for e in ::EventHandler::EventImpl.includers %}{% puts e %}{% end %}... and if I use Mod.includers, this gives me e.g. String.class, whereas if I do Cls.all_subclasses I get just String
<FromGitter> <Blacksmoke16> :shrug:
<hightower2> (in the actual code... not sure why it's not directly reproducible on carc)
<hightower2> ah
<hightower2> this happened after changing include to extend
<FromGitter> <Blacksmoke16> makes sense i guess, prob a but that `.includers` returns types that were `extend`ed
<hightower2> but if that's so, the question is still the same... how to get rid of .class
<FromGitter> <Blacksmoke16> bug*
<FromGitter> <Blacksmoke16> try `.instance`
<hightower2> that seems to have worked for the immediate issue, thanks
<FromGitter> <Blacksmoke16> id file a bug for that
<hightower2> done, but somehow I think the answer will be that it was intentionally made so
<FromGitter> <Blacksmoke16> naw, i added that feature, it wasnt intentional :P
<hightower2> ;-))
<hightower2> Blacksmoke16 but then macros need another method to get the list of classes using 'extend'? At the moment .all_subclasses does not seem to include it, and them being included in .includers you say is an error
<FromGitter> <Blacksmoke16> probably, i remember seeing an issue about it but cant find it atm
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 258 seconds]
chachasmooth has quit [Ping timeout: 268 seconds]
chachasmooth has joined #crystal-lang
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
<FromGitter> <HertzDevil> there shouldn't be any differences between a type extending a module or the type's metaclass including the module, so i'd say that's intended behaviour
<FromGitter> <Blacksmoke16> the name isnt entirely accurate now tho
<FromGitter> <Blacksmoke16> i.e. if i extend a module i wouldnt expect it to show up when calling `.includers`
<FromGitter> <HertzDevil> i do
<FromGitter> <Blacksmoke16> mmm, but you're not including it
<FromGitter> <Blacksmoke16> id be fine with a diff name that covers both, but is a bit unexpected atm
deavmi has quit [Ping timeout: 258 seconds]
deavmi has joined #crystal-lang
_ht has joined #crystal-lang
yxhuvud has quit [Read error: Connection reset by peer]
yxhuvud has joined #crystal-lang
<hightower2> Can a proc somehow call itself? Something like https://carc.in/#/r/a6af
<FromGitter> <error256> IDK about language features, but in terms of functionality recursive anonymous functions can be done like this in many languages: https://carc.in/#/r/a6ap
<hightower2> nice, thanks
Dreamer3 has quit [Quit: Leaving...]
entel is now known as to0n
<oprypin> wait, if `super` and `previous_def` are special in a very special manner, why is `super` widely considered a keyword, and `previous_def` definitely isn't?
to0n is now known as entel
<straight-shoota> oprypin, who doesn't consider previous_def a keyword?
<oprypin> straight-shoota, lexer.cr
<oprypin> also highlighter.cr
<straight-shoota> I suppose there's no reason for that because to the lexer it's just an identifier/call
<oprypin> >> previous_def = 5
<DeBot> oprypin: # => 5 - https://carc.in/#/r/a6bs
<straight-shoota> sure why not?
<straight-shoota> >> initialize = 5
<DeBot> straight-shoota: # => 5 - https://carc.in/#/r/a6bw
<oprypin> >> super = 5
<DeBot> oprypin: # => 5 - https://carc.in/#/r/a6bx
<oprypin> wait what
<straight-shoota> keywords in Crystal are context aware
<oprypin> >> def super; end; def previous_def; end
<DeBot> oprypin: #=> nil - https://carc.in/#/r/a6bz
<oprypin> ok what
<straight-shoota> yeah, that really doesn't make sense because you can't call them
<straight-shoota> #10097
<DeBot> https://github.com/crystal-lang/crystal/pull/10097 (Disallow top-level `def super` and `def previous_def`)
<oprypin> i'm trying to find what difference it makes the fact that lexer.cr has :super but doesnt have :previous_def
<straight-shoota> yeah, probably not much
<oprypin> i dont even know what `forall` is
<oprypin> never mentioned in lexer.cr
<oprypin> what's lexer.cr even used for? lol
<straight-shoota> all work done by parser
<straight-shoota> =)
ua has quit [Ping timeout: 264 seconds]
ua has joined #crystal-lang
MasterdonX has quit [Ping timeout: 264 seconds]
willamin has joined #crystal-lang
<FromGitter> <drum445> I've found a potential problem with the DB driver, I'm hosting a kemal app and the connection is handled using the standard DB.open. The problem is if the app is unused for many hours (overnight) the first request will throw a connection lost error so I've had to add a manual retry
<FromGitter> <drum445> has anyone else experienced this? Not a big deal to add a manual retry, but shouldn't the driver deal with long open connections
<straight-shoota> @drum445 I'd figure this behaviour depends on the exact driver you're using
<FromGitter> <drum445> mysql
<FromGitter> <drum445> am I right in thinking my kemal app should have a global db connection which uses DB.open, instead of calling DB.open per request?
<straight-shoota> yes, totally
<straight-shoota> DB manages connections for you
<FromGitter> <drum445> perfect, so I have a static class that looks like this (I think you may have suggested this a long time ago)
<FromGitter> <drum445> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fe8e72eacd1e516f8b9d374]
<FromGitter> <drum445> Then my controllers that need a DB, simple use DBHelper.maria - does that sound correct?
<straight-shoota> yeah
<straight-shoota> from what I understand, this works correctly for you in general?
<FromGitter> <drum445> It works great, the only problem I've seen is when the app is unused for a while, then the first request after a long time will throw a connection error
<FromGitter> <drum445> the ones after that work, but the first one fails - to fix this I added a test query before returning the DB.open instance
<straight-shoota> so it appears the pools gives you timed out connections after long time of no use
<FromGitter> <drum445> correct
<FromGitter> <drum445> so my DBHelper class runs this `@@maria_con.not_nil!.query "select 'a' 'a' from dual" { |rs| }` and if it fails it reauths before returning the DB.open instance
<straight-shoota> so you do an entire new `DB.open` on failure?
<FromGitter> <drum445> Yeah, I can't see any way round it
<straight-shoota> yeah, there probably isn't
<FromGitter> <drum445> cool, for now running my test query before returning the instance seems reasonable then?
<straight-shoota> hm, actually DB::Pool has some retry logic that should automatically fall back to making a new connection
<straight-shoota> not sure, why that doesn't work four you
<straight-shoota> that method should implicitly be called when you execute a statement on a pool connection
<FromGitter> <drum445> That's what I thought too from looking at the logic here: https://crystal-lang.org/reference/database/connection_pool.html
<FromGitter> <drum445> I think the problem is the pool is completely dead during that first request
<straight-shoota> that shouldn't matter
<straight-shoota> if the pool has no idle connections, it establishes a new one
<FromGitter> <drum445> intersting
<FromGitter> <drum445> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fe8ea8969ee7f0422c8aeb7]
<FromGitter> <drum445> I wonder if that is being hit
<straight-shoota> how exactly do you run your SQL queries?
<FromGitter> <rukkiddo> do you try to connect in each query, or you try to manage the same connection
<straight-shoota> and do you have a stack trace of one of those connection lost errors?
<FromGitter> <drum445> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fe8eaea63fe034496210bd5]
<FromGitter> <drum445> is one example
<FromGitter> <drum445> Don't think I do have the trace anymore
<straight-shoota> okay, so that's definitely a query on the database. So the retry logic should fire
<FromGitter> <drum445> my thoughts too mate, I'm quite stumped by it
<FromGitter> <drum445> @rukkiddo - there is one global connection and all repo classes use that
<FromGitter> <drum445> `"?max_pool_size=50&initial_pool_size=2&max_idle_pool_size=2&retry_attempts=3"` - is my config
<FromGitter> <drum445> I tried adding `retry_delay` but it didn't change anything
_ht has quit [Remote host closed the connection]
kevinsjoberg has quit [Ping timeout: 260 seconds]
r0bby has quit [Ping timeout: 260 seconds]
repo has quit [Ping timeout: 260 seconds]
kevinsjoberg has joined #crystal-lang
r0bby has joined #crystal-lang
repo has joined #crystal-lang
teardown has joined #crystal-lang