ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | 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
ur5us_ has quit [Ping timeout: 248 seconds]
ur5us_ has joined #crystal-lang
Stephie has quit [Quit: Fuck this shit, I'm out!]
Vexatos_ has quit [Quit: Client Quit]
yxhuvud has quit [Remote host closed the connection]
Vexatos has joined #crystal-lang
Stephie has joined #crystal-lang
xyhuvud has joined #crystal-lang
ur5us_ has quit [Remote host closed the connection]
ur5us_ has joined #crystal-lang
ur5us_ has quit [Ping timeout: 255 seconds]
quazimodo has joined #crystal-lang
Sankalp has quit [Ping timeout: 260 seconds]
Sankalp has joined #crystal-lang
quazimodo has quit [Ping timeout: 260 seconds]
_ht has joined #crystal-lang
<FromGitter> <azurelmao> Is it possible to make custom types splattable?
mjblack1 has joined #crystal-lang
mjblack has quit [Ping timeout: 248 seconds]
taupiqueur1 has quit [Quit: WeeChat 3.8]
<FromGitter> <oprypin:matrix.org> @azurelmao: sure, just needs to implement Iterable
hightower2 has quit [Remote host closed the connection]
hightower2 has joined #crystal-lang
renich has quit [Remote host closed the connection]
jmdaemon has quit [Ping timeout: 260 seconds]
<FromGitter> <Blacksmoke16> Wait really? That's all you have to do? 👀
hightower2 has quit [Ping timeout: 268 seconds]
hightower2 has joined #crystal-lang
<FromGitter> <Blacksmoke16> mm no has to be something else... ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=63e8ecf5a2d58f2e4873edaf]
<FromGitter> <azurelmao> how do I communicate between a spawned thread and the main one?
<FromGitter> <azurelmao> I tried using those channels like in the guide but they block the main thread from executing
<FromGitter> <azurelmao> i want both of them to be running at full speed
<FromGitter> <azurelmao> and whenever the spawned thread finished it tells the main thread
<FromGitter> <moe:busyloop.net> sounds like you may want a queue: https://crystal-lang.org/api/1.7.2/Deque.html
<xyhuvud> Deques are not thread safe though. I'd look for ways to restructure so that channels, or channels with a capacity, is possible.
<FromGitter> <moe:busyloop.net> oh, somehow i had assumed they are
<FromGitter> <moe:busyloop.net> should def put some warnings about what is and isn't threadsafe in the docs before MT lands 😅
<FromGitter> <moe:busyloop.net> as long as MT is off, Deque across fibers should work tho, right? (i think i've relied on that somewhere in the past 🤔)
<FromGitter> <jrei:matrix.org> Lots of data structures aren't thread safe in Crystal
<FromGitter> <jrei:matrix.org> The safe way is to use channels
<FromGitter> <moe:busyloop.net> hm yea, looks like Deque isn't fiber-safe even in the little test i just made 😞
<FromGitter> <moe:busyloop.net> err disregard my last msg. Deque looks fibersafe (at least in the little test i just made)
<FromGitter> <azurelmao> > as long as MT is off, Deque across fibers should work tho, right? (i think i've relied on that somewhere in the past 🤔) ⏎ ⏎ what if MT is on
<FromGitter> <azurelmao> which it is
<FromGitter> <moe:busyloop.net> for Deque you can try it out with this snippet: https://carc.in/#/r/ejv9
<FromGitter> <moe:busyloop.net> (likely wanna use a larger value that `10.times` - just had to made that small cause carc.in runs on raspberry)
<FromGitter> <moe:busyloop.net> my guess is that on MT it will crash & burn unless you uncomment the mutex
<FromGitter> <moe:busyloop.net> but don't have a MT binary to test myself
<FromGitter> <azurelmao> > for Deque you can try it out with this snippet: https://carc.in/#/r/ejv9 ⏎ ⏎ which parts of the code can I remove? I don't quite understand what's going on there
<FromGitter> <moe:busyloop.net> nothing, just run `crystal snippet.cr` with or without MT. *with* MT it'll likely throw some error, *without* MT it works.
<FromGitter> <azurelmao> oh, I thought you gave me some example code to use
<FromGitter> <moe:busyloop.net> to make it also work on MT, you can uncomment the lines that are currently commented out (those wrap the deque access in a lock)
<FromGitter> <azurelmao> seems to work even without the mtx
<FromGitter> <moe:busyloop.net> no, sorry, i was just testing my assumption of Deque being fibersafe without using locks (it is). ⏎ if you want to use it with MT enabled then you need to wrap it in locks (the part that is commented out in my snippet).
<FromGitter> <moe:busyloop.net> even when you increase `10.times` -> `12456.times`? 🤔
<FromGitter> <azurelmao> oh, nvm I used "Run current file" to run it which is without mt enabled
<FromGitter> <moe:busyloop.net> right. even if it happens to work in MT, i wouldn't rely on it. (if you want to use Deque in MT then use locks)
<FromGitter> <azurelmao> is there an easier way if I just want to transmit Bool?
<FromGitter> <azurelmao> like i wont be putting any data in the deques
<FromGitter> <moe:busyloop.net> i'm not familiar enough with MT to say for sure. ⏎ maybe you can just set `@foo = true` from within the thread (i just don't know if it blows up when multiple threads do that simultaneously)
<FromGitter> <moe:busyloop.net> fwiw, MT is still marked as "preview" for a reason. if you wanna use it then i'd rather play it safe and either use `Channel` or liberally wrap things in mutexes.
brw has quit [Quit: Ping timeout (120 seconds)]
brw has joined #crystal-lang
<FromGitter> <jrei:matrix.org> To be sure, you use `-preview_mt`?
<FromGitter> <azurelmao> -Dpreview_mt
<FromGitter> <azurelmao> is it different?
<FromGitter> <azurelmao> @moe:busyloop.net btw I made a mutex and put .synchronize in the places where i assign and access it
<FromGitter> <azurelmao> and now it works correctly
<FromGitter> <azurelmao> oh I just realized i didnt tell you what I needed it for
<FromGitter> <azurelmao> ill show you
<FromGitter> <azurelmao> https://streamable.com/ja69go
<FromGitter> <azurelmao> previously it would sometimes read the mesh buffer while still incomplete
<FromGitter> <jrei:matrix.org> Yes that this flag
<FromGitter> <jrei:matrix.org> Indeed `Mutex` is the way
ur5us_ has joined #crystal-lang
<FromGitter> <moe:busyloop.net> no idea what that is, but def looks cool :)
ur5us_ has quit [Ping timeout: 255 seconds]
ur5us_ has joined #crystal-lang
_ht has quit [Quit: _ht]
jmdaemon has joined #crystal-lang
quazimodo has joined #crystal-lang
bastienleonard has joined #crystal-lang
<bastienleonard> hi, is there a simpler way of converting an integer to its char representation than this? n.to_s.each_char.first (0 <= n <= 9)