<krystal>
Question about dealing with union types that contain Nil. For example Http::Request.query. If no query parameters are set this is Nil . You can't write code like if (context.request.query && context.request.query.SomeStringFunction) . You can do if q = context.request.query and then another if statement. What is the canonical Crystal way to handle things like this?
<FromGitter>
<ezrast> @krystal Either what you said, or `context.request.query.try &.some_string_function`
<krystal>
Thanks I didn't notice try before. It's not referenced anywhere in the main docs. May be nice to put it on the Union types page or Nil page maybe?
<krystal>
nevermind it's in the same section i got the other solution from :)
<FromGitter>
<girng> https://stackoverflow.com/a/29885992/7873241 Is this answer an accurate description of how heap memory works within a Crystal app? I know it says nodejs, but I was testing my tcp server on crystal, and then in a nodejs one. And in fact, they do the same thing. They "Plateau" to a certain amount of memory, but don't go down. But it doesn't mean it's a memory leak, it just means the OS then has to determine when it
<FromGitter>
... wants that memory back. Under extreme stress, etc. If I got that right, I think? :)
<FromGitter>
<girng> When he says "heap manager", is he referring to a garbage collector?
ua has quit [Quit: Leaving]
ua has joined #crystal-lang
qard has joined #crystal-lang
Guest3612 is now known as baweaver
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
qard has quit [Quit: qard]
<FromGitter>
<Grabli66> Hi! How to close all forked processes?
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
DTZUZO has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 248 seconds]
Nik736 has joined #crystal-lang
rohitpaulk has joined #crystal-lang
Nik736 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<yorci> hey all, Crypto::Bcrypt::Password is terribly slow, any improvements plan ?
<FromGitter>
<sdogruyol> there's an issue about it
<FromGitter>
<sdogruyol> but it shouldn't be terribly slow?
<FromGitter>
<bew> The same goes for stream/dgram/others sockets, they must be used differently based on their socket type (I have no idea how to make that cleanly though)
<RX14>
we should provide a `Crystal::System::Socket` with all the BSD socket primitives
<RX14>
then wrappers for {UDP,TCP}{Server,Client}
<RX14>
oh
<RX14>
and UNIX?
<RX14>
but UNIX sockets can be any proto right
<RX14>
so unix sockets should just be UDP or TCP server/clients?
<RX14>
and just deal with the bad naming
<RX14>
we could call it StreamServer.{tcp,unix}
<RX14>
but that would be hard to discover in the docs
<RX14>
because people aren't used to thinking stream/datagram instead of tcp/udp
<FromGitter>
<Grabli66> Maybe don't do this? Everything is working now. And it's need a lot of time to rework, i think :)
<RX14>
no
<RX14>
why would we release 1.0 with a known-substandard interface
<FromGitter>
<Grabli66> Great. I just tested your will. 😄
<RX14>
guess it's time to stop procrastinating writing the 0.25.0 changelog
<FromGitter>
<Grabli66> It's time to write some code
<FromGitter>
<bew> RX14 do you have some control on the google group?
<FromGitter>
<bew> RX14 why zmq for simple IPC, pipes not enough?
snsei has joined #crystal-lang
<RX14>
hmm
<RX14>
i'm not certain of the best way to do this to be honest
<RX14>
the thing is locking on the FDs
<RX14>
we want atomic sends and recieves
<RX14>
so you'd need locking on the pipe
<RX14>
which means the locks would have to be in shm
<RX14>
and then somehow you'd have to integrate the locks into the event loop? eugh
<FromGitter>
<bew> didn't thought about that
That_Guy_Anon has quit [Remote host closed the connection]
<FromGitter>
<girng> Nice! So I'm doing some testing with my socket.cr and server.cr. I bought a new KVM VPS, and their cpu specs are here (https://i.gyazo.com/8795db56419e8434eda7c26ab1a5092f.png). I am not sure how much is actually given through a "Virtual Core". But I changed my `socket.cr` to send a message to the server every 6 seconds. I loaded up 8,000 connections (https://i.imgur.com/kpl3zOX.png).
<FromGitter>
<bew> I'm not sure it's what you want, it seems you can't send data with eventfd
<RX14>
i know
<FromGitter>
<bew> ah you want to use that in addition to pipe?
<RX14>
yeah you'd have to
<RX14>
actually
<RX14>
maybe not
<RX14>
(lol)
<RX14>
might be able to do it entirely with shm and atomics
<RX14>
each process would have a shm pool which was mapped into every other process
<RX14>
(assuming that can be done, which is shard)
<RX14>
the PChan is allocated in that shm pool
<RX14>
senders serialize their objects to shm
<RX14>
then attempt to spinlock on ...
<RX14>
no this wouldn't work
<RX14>
you essentially need a readers lock and a writers lock and a pipe
<RX14>
and the reader and writers locks need to be put into the evnt loop
<RX14>
the pipe can be replaced with shm
<RX14>
but the locks needs to be evented
<RX14>
nope, the locks AND the pipe need to be evented?
faustinoaq has joined #crystal-lang
<RX14>
nope we need eventfd and pipe
<RX14>
this is actually a hard problem
<RX14>
you could probably replace the pipe with shm if readers tried to acquire the write lock as well?
<RX14>
and thats all only for unbuffered pipes
<RX14>
buffered pipes are a whole new can of worms lol
<RX14>
i think i need to work this design out on paper
shalmezad has quit [Quit: Leaving]
<FromGitter>
<bew> I like the idea of using shm to pass the data! but this can work only in one direction, right? so you'd need 2 for bidirectional communication
That_Guy_Anon has joined #crystal-lang
faustinoaq has quit [Ping timeout: 248 seconds]
<RX14>
well yeah
<RX14>
channels only work in one direction
<RX14>
and how often do you find that a problem
<FromGitter>
<bew> hm yeah not a problem actually, if you want bidirectional you make 2 channel..
<FromGitter>
<bew> RX14 do you think macros are slow?
<RX14>
i know they're slow
<RX14>
lol
<FromGitter>
<bew> hmm yes obviously :P I'm thinking about extracting the literal expansion out of the compiler, and using macros in the stdlib for that, I need to bench that see if it's horrible or not
<FromGitter>
<bew> would be nice to be able to put annotations on macros :P
<FromGitter>
<bew> like `@[LiteralExpander(ArrayLiteral, when: (node.of && node.size == 0))]` on top of my macro for that
<FromGitter>
<bew> yeah maybe not that good of an idea.. I was thinking about making the compiler more stdlib agnostic, so that you can build your own library for the same language, that could work differently, different classes (and maybe only structs), can disallow some literal by raising on their expansion, ....
<RX14>
yeha that'd be cool
<RX14>
but
<RX14>
thats not the place to start
<FromGitter>
<bew> it's just an idea I got a few days ago, wanted to try it out
<FromGitter>
<manveru> is there some way to make errors like `in server.cr:188: instance variable '@last_value' of Boxes::Box(NamedTuple(display: String, headers: String, rows: Array(Array(String)))) must be NamedTuple(display: String, headers: String, rows: Array(Array(String))), not NamedTuple(display: String, headers: Array(String), rows: Array(Array(String)))` display more like ⏎ ⏎ ```code paste, see link```
<FromGitter>
<manveru> so it's easier to see the issue?
<Yxhuvud>
well, if you know the type of a likely error (or a likely too broad error) you can make an error overload that fits the error and raise during ompile time with the error you want
<FromGitter>
<manveru> i meant more... language wide
<FromGitter>
<manveru> i know the better way is to make a type alias, but i sometimes encounter such errors that run a few lines and i have to put in a text editor to decipher
wontruefree has quit [Quit: bye]
<Yxhuvud>
well, sometimes it is quite conventient to type method arguments or return values to fence in the issues
<FromGitter>
<bew> I think you can open an issue about that, see how it goes ;)
sz0 has joined #crystal-lang
snsei has quit []
wontruefree has joined #crystal-lang
RX14 is now known as Loki_Laufeysdott
Loki_Laufeysdott is now known as RX14
snsei has joined #crystal-lang
wontruefree has quit [Client Quit]
That_Guy_Anon has quit [Quit: Leaving]
wontruefree has joined #crystal-lang
notdaniel has joined #crystal-lang
wontruefree has quit [Quit: bye]
<FromGitter>
<manveru> given `@boxes : Array(Boxes::Text | Boxes::Images | Boxes::Table | Boxes::Iframe)`, is there a way to make a macro that creates that union for all subclasses of `Boxes::Box` instead?
<FromGitter>
<manveru> i'm not sure how i'd create a new `Crystal::Macros::Union` instance
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
notdaniel has quit [Ping timeout: 252 seconds]
<FromGitter>
<bew> Just `Type1 | Type2`
<FromGitter>
<bew> You can also make an `Array(Box) `
<FromGitter>
<manveru> my problem is that `Box` is actually a `Box(T)`, so `Array(Box)` won't compile
<FromGitter>
<manveru> so, i know i can write them all by hand, but i was wondering if this is something possible with macros :)
<FromGitter>
<manveru> oh well, it was worth a try, but seems like this is some kind of compiler bug because that's clearly a subset, so it should be fine?
go|dfish has quit [Ping timeout: 268 seconds]
<FromGitter>
<bew> How is that a compiler bug ?
<FromGitter>
<bew> Ah
<FromGitter>
<bew> No, `Array(X)` is different than `Array(X | Y)`, that's how things currently are