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
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f6fd788efefe620f24f5e24]
<FromGitter> <Blacksmoke16> got some of it integrated into rest of Athena now, turned out quite nice if i must say so myself :p
<FromGitter> <Blacksmoke16> sorry `Foo` is a custom assertion that checks if the value `== "foo"`
antoszka_ has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 264 seconds]
z64 has quit [*.net *.split]
antoszka has quit [*.net *.split]
PixeLInc_ has quit [*.net *.split]
<FromGitter> <Blacksmoke16> updated `property` field to include information about root object, `"property": "Object(Foo).name",`
<FromGitter> <Blacksmoke16> also correctly handles hash and array key/indices
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
chachasmooth has quit [Ping timeout: 240 seconds]
chachasmooth has joined #crystal-lang
z64 has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
f1reflyylmao has quit [Quit: bye fags]
f1refly has joined #crystal-lang
zorp has quit [Ping timeout: 265 seconds]
dead10cc has joined #crystal-lang
dead10cc has left #crystal-lang [#crystal-lang]
_whitelogger has joined #crystal-lang
PixeLInc has joined #crystal-lang
<FromGitter> <Nicolab> @maxbertinetti I saw this but it doesn't work at my house and at a colleague's, I don't know why (when I ctrl + space there is always the same message, I don't remember which one. As soon as I retest I let know).
<FromGitter> <Nicolab> @maxbertinetti I just tested, each ctrl+space displays the message "Loading...".
<FromGitter> <Nicolab> on hover I have the message : `Unsupported Markup content received. Kind is:`
<FromGitter> <Nicolab> And with Crystalline: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f7045cf5b75b305ddca6764]
<raz> blacksmoke16: now the hard part. how does it work with my ORM? :P
<raz> j/k, i think targeting a specific orm is fine
<FromGitter> <Nicolab> @raz what is your ORM?
alexherbo2 has joined #crystal-lang
alexherbo24 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo24 is now known as alexherbo2
<raz> oh, i meant that as "my fav orm"
<raz> hinting at orm pluggability. but wasn't serious, that should prob not be a goal (or only much later)
<FromGitter> <maxbertinetti> @Nicolab for Crystalline try to use the new binary. Remove anything in VSCode that can conflict with the two packages.
<FromGitter> <maxbertinetti> @Nicolab which OS you are running?
<FromGitter> <Blacksmoke16> raz: it should work with any orm. However only granite would support the annotation approach. The others would have to do it via code manually
<FromGitter> <Blacksmoke16> Well probably could use annotations but would probably have to like retype the ivar and apply it if you're not able to apply it directly to the column def
alexherbo2 has quit [Ping timeout: 246 seconds]
yxhuvud has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang
yxhuvud has joined #crystal-lang
<FromGitter> <herrcykel> Hi people! I have a piece of code that no longer works after upgrading crystal. 0.33 seems to be the breaking point. The code uses inotify api to watch for new files in a directory. The first issue is a Proc not being called when doing `spawn proc.call(arg)`, 2nd is Ctrl-C no longer being trapped. The code can be tested by running it and then creating a file in the working directory, which should show the
<FromGitter> ... different behavior between docker images `crystallang/crystal:0.32.1` and `crystallang/crystal:0.33.0`
<FromGitter> <herrcykel> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f709c58e1dd7c19549b96c2]
<FromGitter> <herrcykel> Relevant parts should be `start` method and below. Any help appreciated!
<raz> blacksmoke16: yea no worries. focus on a package that works. rest can come later. rails, django etc. are successful because they come w/ batteries included.
<FromGitter> <Blacksmoke16> @herrcykel maybe try to reduce the code? Like is all that C stuff required to replicate the issue?
<FromGitter> <Blacksmoke16> raz: thats how i been making all my stuff 😉 this ones the fanciest tho. Learned some new patterns that have been treating me well
<FromGitter> <Blacksmoke16> ```code paste, see link``` ⏎ ⏎ Like this is what gets included into the type. Was able to move the logic of iterating ivars and stuff into the metadata class itself, versus like building that out and returning an array [https://gitter.im/crystal-lang/crystal?at=5f70a6066a6e094525bd3a21]
<FromGitter> <Blacksmoke16> its also cached so only is built once when that type first goes to be validated
<FromGitter> <herrcykel> @Blacksmoke16 ya sorry ik it's a bit much. I did try to replace waiting for a file to be created with waiting for data on a socket but that does not replicate the issue :(
<FromGitter> <herrcykel> This works as expected: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f70aaaa417bf140aa17edc3]
<FromGitter> <herrcykel> Not sure if it's due to being inside the `server.accept` block
<FromGitter> <Blacksmoke16> Hmm
<FromGitter> <Blacksmoke16> What happens if you add a Fiber.yield after the spawn proc.call
<FromGitter> <herrcykel> Ha nice, that made the proc run! Thanks!!
<FromGitter> <Blacksmoke16> if i had to guess there was never anything in the loop that blocked the fiber, so it never could switch
<FromGitter> <Blacksmoke16> however im not sold on if that should be the solution, or refactor things so you dont need to do that :shrug:
<FromGitter> <naqvis> `Fiber.yield` will tell the scheduler to execute the other fiber. As main Fiber is in sleep mode, while other fiber is under tight loop, so definitely would require a way to notify scheduler to execute other fiber
<FromGitter> <herrcykel> Hm I believe the loop is being blocked. I changed the code to ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f70aeeb0b5f3873c9f7881f]
<FromGitter> <herrcykel> And the output is ``` ⏎ Before read... ⏎ After read ⏎ This is printed in crystal 0.32 and 0.33 ⏎ This is printed in crystal 0.32 ... [https://gitter.im/crystal-lang/crystal?at=5f70aefab8a99f4519ae60b8]
<FromGitter> <naqvis> also better to move `proc` code above the loop, as it doesn't make sense to create this in loop (assuming you won't be changing the contents of this proc during that loop), its just argument which is different ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f70af006a6e094525bd5133]
<FromGitter> <naqvis> another thing, your proc is accepting a `String` while `full_name` is `String?`, so you would need to call `full_name.not_nil!` when calling this proc
<FromGitter> <Blacksmoke16> he did have a `next if full_name.nil?` which would prob handle that
<FromGitter> <naqvis> yeah, but he is calling the proc beneath that and don't think compiler will be assuming that var beneath this line is not null
<FromGitter> <Blacksmoke16> :shrug: dunno
<FromGitter> <herrcykel> Ctrl-C not working is still an issue. Any ideas?
<FromGitter> <herrcykel> Ty for helping out!
<FromGitter> <naqvis> `Signal::INT.reset` try this
<FromGitter> <herrcykel> Before `Signal::INT.trap ...`? Made no difference
<FromGitter> <naqvis> after
<FromGitter> <naqvis> :P
<FromGitter> <naqvis> @Blacksmoke16 you are right, compiler is smart enough to not treat optional variable as nil, beneath `next if name.nil?` check. https://play.crystal-lang.org/#/r/9rcy
<FromGitter> <Blacksmoke16> 👍
zorp has joined #crystal-lang
<FromGitter> <herrcykel> @naqvis `reset` makes Ctrl-C terminate the program. Same effect as having no `Signal::INT.trap`, which is expected I guess
<FromGitter> <herrcykel> Hm, confused why `Signal::INT.trap` isn't catching anything
<FromGitter> <naqvis> I just played around and notice that sigint doesn't work with Fibers in place
<FromGitter> <naqvis> if no Fiber, it works perfectly fine, but as soon as Fiber is added, this trap doesn't work
<FromGitter> <naqvis> for example, this code will run forever, until killed the process ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f70b64df41f4105e4deea0b]
<FromGitter> <herrcykel> Huh, I just tried that code on 0.32 and it's not getting trapped there either
<FromGitter> <herrcykel> Reduced the test case to: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f70b8306a6e094525bd67b0]
<FromGitter> <Blacksmoke16> what happens if you put that in the `spawn do` block?
<FromGitter> <Blacksmoke16> put it*
<FromGitter> <herrcykel> No difference :/
<FromGitter> <Blacksmoke16> rip, well im out of ideas
<FromGitter> <naqvis> well, i just figured out that you will need to put fiber in some suspended state for it to give some breathing time to other events :P
<FromGitter> <naqvis> ```loop do ⏎ sleep 0.1 ⏎ ...... ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f70bb635efe9467b11cb89e]
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> try doing `sleep 0`
<FromGitter> <naqvis> also notice `reader.read(data)` is blocking call, if you hit `ctrl-c` while no event data has been read by this call, it will still pause, but as soon as this call returns, code inside `Signal::INT.trap` block get executed
<FromGitter> <naqvis> sleep 0 works as well
<FromGitter> <herrcykel> The trap works in 0.33 too if I use fd 0 instead of the one returned from `inotify_init`
HumanGeek has quit [Ping timeout: 256 seconds]
HumanGeek has joined #crystal-lang
<FromGitter> <naqvis> @herrcykel Got the reason of why it isn't catching the sigint :P
<FromGitter> <naqvis> the reason is `IO::FileDescriptor` created is blocking and it hold the fiber in blocking mode.
<FromGitter> <naqvis> you should set it to non-blocking via setting the blocking property to false ⏎ ⏎ ``` reader = IO::FileDescriptor.new(@fd) ⏎ reader.blocking = false``` [https://gitter.im/crystal-lang/crystal?at=5f70c7b5efefe620f2519b3f]
<FromGitter> <naqvis> rest remains same
<FromGitter> <naqvis> also in this way you won't need to add `Fiber.yield`
Human_G33k has joined #crystal-lang
HumanGeek has quit [Ping timeout: 240 seconds]
<FromGitter> <naqvis> or simply via `reader = IO::FileDescriptor.new(@fd,false)`
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
Human_G33k has quit [Ping timeout: 272 seconds]
<FromGitter> <herrcykel> @naqvis ohhh thank you so much!! All good now!
<FromGitter> <naqvis> 👍
Human_G33k has joined #crystal-lang
<FromGitter> <herrcykel> Seems like `reader.read(data)` is still blocking tho? I would expect it to immediately return if it's non-blocking
<FromGitter> <herrcykel> Just trying to understand what changed :)
<yxhuvud> What kind of file is it?
<FromGitter> <herrcykel> It's the fd from https://linux.die.net/man/2/inotify_init
<FromGitter> <naqvis> @herrcykel you better use `int inotify_init1(int flags);` instead of first version or else you should call ⏎ ⏎ ```if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) // error checking for fcntl ⏎ exit(2);``` [https://gitter.im/crystal-lang/crystal?at=5f70d143417bf140aa18471d]
<FromGitter> <naqvis> `IO::FileDescriptor` blocking will be different from file descriptor you retrieve via `inotify_init`
<FromGitter> <naqvis> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f70d1c90b5f3873c9f7d8fe]
<yxhuvud> naqvis: he sets it to not block, and that should emit that fcntl.
<yxhuvud> One thing though, is that it will use buffered IO when used like that. Might not be good for the use case.
<FromGitter> <naqvis> yxhuvud you are saying that `IO::FileDescriptor` will invoke `fnctl` when `blocking` set to false?
<FromGitter> <naqvis> unfortunately that isn't the case
<FromGitter> <naqvis> aha
<FromGitter> <naqvis> thanks yxhuvud
<FromGitter> <naqvis> so using `inotify_init1` will not require manually setting `blocking` to false
<FromGitter> <naqvis> yxhuvud this was the initial question from herrcykel ☝️ September 27, 2020 10:05 PM (https://gitter.im/crystal-lang/crystal?at=5f709c32f41f4105e4dea956)
<yxhuvud> well, can't see anything obvious in the changelog
<FromGitter> <herrcykel> https://github.com/crystal-lang/crystal/commit/9c30c260a17bcc6a0fad0f109f8858a307a590a7#diff-97b852ed0df274031d263857a85db195R12 that's where it changed to not have `blocking = false` by default
<FromGitter> <herrcykel> Unless you're referring to some other change :)
alexherbo28 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 256 seconds]
alexherbo28 is now known as alexherbo2
<FromGitter> <naqvis> @herrcykel Seems Linux Kernel changes is causing that, I just tested the code with `C.inotify_init1(C::O_NONBLOCK)` and it works without any further change to your code
<FromGitter> <naqvis> you don't need to call `blocking = false`
<FromGitter> <naqvis> this is what I added to your code ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ rest code remains same [https://gitter.im/crystal-lang/crystal?at=5f70db6c5a56b467a5f37b51]
<FromGitter> <herrcykel> Is it better than `blocking = false`?
<FromGitter> <naqvis> yeah, as this will avoid call to `fnctl` :P
<FromGitter> <naqvis> according to inotify_init manpage `Using this flag saves extra calls to fcntl(2) to achieve the same result.`
<FromGitter> <herrcykel> Ha, ok then!
<FromGitter> <herrcykel> Thanks to all of you, again!
_whitelogger has joined #crystal-lang
alexherbo28 has joined #crystal-lang
alexherbo28 has quit [Excess Flood]
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo26 has joined #crystal-lang
<oprypin> is there any shorthand for `def foo? : Foo?; x; end; def foo; foo?.not_nil!; end`
<FromGitter> <Blacksmoke16> `getter!` i think?
<oprypin> Blacksmoke16, getter! uses `@foo` rather than `foo?` i think
<oprypin> lol how do i debug it https://carc.in/#/r/9rda
<oprypin> yea so getter implies making an instance varialbe but i dont want that
<FromGitter> <Blacksmoke16> yea not a thing then
<FromGitter> <Blacksmoke16> those macros assume they define ivars
<FromGitter> <Blacksmoke16> could make your own macro tho, or just not worry about it
<oprypin> right
_whitelogger has joined #crystal-lang
<oprypin> how can i sort an array of nilables with the definiton that nil compares the smallest?
<FromGitter> <Nicolab> @maxbertinetti I'm on Ubuntu 18.04
<oprypin> found this """gem""" https://stackoverflow.com/a/808694
<FromGitter> <Nicolab> @maxbertinetti : ⏎ ⏎ VS code ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f7111b50b5f3873c9f8698c]