<< 15-12-2023 >>

00:03:37*mahlon joined #nim
00:32:19*xet7 joined #nim
00:54:11*azimut quit (Remote host closed the connection)
00:54:33*azimut joined #nim
01:36:24*sagax quit (Quit: Konversation terminated!)
01:51:09*Jjp137 quit (Remote host closed the connection)
01:54:28*Jjp137 joined #nim
03:07:59*xet7 quit (Ping timeout: 256 seconds)
03:47:45*edr quit (Quit: Leaving)
04:19:00FromDiscord<ringabout> Nim intern strings plan is postponed because it cannot work with `cstring` without breaking everything
06:56:16*cnx quit (Remote host closed the connection)
06:57:07*cnx joined #nim
07:08:58*advesperacit joined #nim
07:50:40*PMunch joined #nim
08:13:41FromDiscord<alireza0x0> guys
08:13:55FromDiscord<alireza0x0> anyone knows why this code conusems 86% of my pc cpu?
08:13:57FromDiscord<alireza0x0> https://media.discordapp.net/attachments/371759389889003532/1185132628769243245/image.png?ex=658e7fc5&is=657c0ac5&hm=1205393e2c2b069e98f256a78dcd6d6a3d1cc3669766adcc1322dd87a7276f80&
08:14:07FromDiscord<alireza0x0> (edit) "conusems" => "consumes"
08:14:30FromDiscord<alireza0x0> cpuRelax is from std/atomics which are used also in ticketlocks and otherplaces so i just copied from there...
08:18:41FromDiscord<nnsee> cpuRelax simply tells the compiler to not clobber memory, ie if you're reading some value in the while loop
08:18:51FromDiscord<nnsee> you're still running a `while true` loop
08:19:08FromDiscord<alireza0x0> hmm...
08:19:29FromDiscord<alireza0x0> i tut there is a function that i can run inside my while loop and that stops cosuming cpu ...
08:19:42FromDiscord<alireza0x0> probably no such fuction exist (non blocking)
08:19:52FromDiscord<alireza0x0> (edit) "fuction" => "function"
08:20:00PMunchAs long as you're spinning you're consuming CPU
08:20:11PMunchThat's just the nature of spinning
08:20:14FromDiscord<Elegantbeef> Yea you need to wait for something
08:20:29FromDiscord<alireza0x0> hmm
08:20:35FromDiscord<Elegantbeef> Generally with threads you're waiting on IO or channels
08:20:45FromDiscord<alireza0x0> yea...
08:20:55FromDiscord<alireza0x0> i wanted to mix a channel with async await
08:21:11FromDiscord<alireza0x0> channel only has wait or tryrecv
08:21:23FromDiscord<alireza0x0> 1 of them blocks the event loop compeletly
08:21:32FromDiscord<alireza0x0> other one needs to be run on a loop or eventloop
08:21:33FromDiscord<Elegantbeef> Of course it does
08:21:47FromDiscord<alireza0x0> the poll() function
08:21:53FromDiscord<alireza0x0> inside runforever
08:21:56FromDiscord<alireza0x0> is in a while
08:21:59FromDiscord<alireza0x0> but interestingly
08:22:02FromDiscord<alireza0x0> its not consuming cpu
08:22:07FromDiscord<alireza0x0> and i ran it and test it
08:22:15FromDiscord<alireza0x0> it blocks (puts thread to sleep or something)
08:22:26PMunchpoll has a default timeout of 500ms I believe
08:22:29FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=html>
08:22:36FromDiscord<alireza0x0> that is also very weird... i was hoping i can put my tryrecv inside poll ...
08:22:45PMunchSo it will sleep on a selector for that amount of time
08:23:03FromDiscord<alireza0x0> oh...
08:23:14FromDiscord<Elegantbeef> You need to wrap `tryRecv` with async to get that to work
08:23:19FromDiscord<Elegantbeef> Good luck there
08:23:30FromDiscord<alireza0x0> i think i have to somehow
08:23:36FromDiscord<alireza0x0> register that to the selector right?
08:23:38FromDiscord<alireza0x0> how...?
08:23:48FromDiscord<alireza0x0> well i think
08:24:00FromDiscord<alireza0x0> there is conditions and chronos has kinda asynccontions...
08:24:18FromDiscord<alireza0x0> they also provided a compelx test , i need to read that probably that can solve this...
08:24:28FromDiscord<alireza0x0> (edit) "asynccontions..." => "asyncconditions..."
08:29:36PMunchWhat exactly are you trying to do?
08:29:41PMunchI've mixed threads and async in the past
08:30:01FromDiscord<Phil> Not writing a threadServer that's for sure, because for that one you wouldn't want/need async ^^
08:30:20FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=html>
08:30:40FromDiscord<Elegantbeef> Whoops forgot a `await sleep(x)` at the end
08:30:45FromDiscord<alireza0x0> i want to write a multithreaded server with async/await features inside each thread
08:30:51FromDiscord<alireza0x0> not really a server but a tunnel
08:31:02PMunchThat's not really specific though
08:31:06FromDiscord<alireza0x0> one threads receives and after some process puts the result on the channel
08:31:15FromDiscord<Phil> In reply to @Elegantbeef "The dumbest way is": Throw away the async and you mostly have how I'm implementing my threadserver
08:31:19FromDiscord<alireza0x0> the seccond thread porcess further then writes to other socket
08:32:22FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=html>
08:32:34FromDiscord<Phil> (edit)
08:33:21PMunchWith the little information you have given you can just set up a bog-standard async server, and on every message write them to a channel
08:33:41FromDiscord<Phil> Every thread has its own dispatcher, right?
08:33:44PMunchalireza0x0§ *
08:33:50FromDiscord<alireza0x0> yes
08:33:54FromDiscord<Phil> Or do threads share dispatchers/queues ?
08:33:54PMunchYes, the dispatcher is a threadvar
08:33:57FromDiscord<alireza0x0> every thread has a eventloop
08:34:12FromDiscord<alireza0x0> the thing i want is
08:34:26FromDiscord<alireza0x0> receive some tcp bytse from socket
08:34:29FromDiscord<alireza0x0> put it on a channel
08:34:31FromDiscord<Phil> So you couldn't execute the tasks in the queue of thread A from thread B
08:34:33FromDiscord<Phil> (edit) "B" => "B?"
08:34:37FromDiscord<alireza0x0> otherthread gets notified and reads that bytse
08:34:40FromDiscord<alireza0x0> (edit) "bytse" => "bytes"
08:34:45FromDiscord<alireza0x0> but also asyncrounsly
08:35:10FromDiscord<alireza0x0> im not using thread poll
08:35:13FromDiscord<alireza0x0> (edit) "poll" => "pool"
08:35:23FromDiscord<alireza0x0> il create 2 threads at least to start
08:35:39FromDiscord<alireza0x0> each thread is worknig with a different scoket, they listen on different ports
08:35:45FromDiscord<Phil> I mean except for the async part that sounds very much like what I'm doing
08:36:08FromDiscord<Phil> I guess I could add a call to poll() in my threadButler loop to enable async code execution within a handler
08:36:47FromDiscord<alireza0x0> i guses i should create a different channel type for this usecase
08:37:45FromDiscord<Phil> Ohhhhh using poll() instead of sleep() to break up the while-loop execution to not have it go 100% all the time is actually way better
08:37:55FromDiscord<Phil> (edit) "Ohhhhh using poll() instead of sleep() to break up the while-loop execution to not have it go 100% ... all" added "CPU usage"
08:38:15FromDiscord<alireza0x0> poll blocks also for 1 sec or half
08:38:21FromDiscord<Elegantbeef> Oh phil I got bored, just finished my first pass of a mocking api that works for generics 😜
08:38:23FromDiscord<Phil> 500ms and you can set that timeout
08:38:34FromDiscord<Phil> In reply to @Elegantbeef "Oh phil I got": Angel choirs
08:38:42FromDiscord<Phil> Is that a halo appearing over your head?
08:38:42FromDiscord<alireza0x0> if you set it lower that will consume more cpu
08:38:43FromDiscord<Elegantbeef> It took like 20 minutes
08:38:45FromDiscord<Elegantbeef> Maybe 40
08:38:54FromDiscord<Elegantbeef> https://github.com/beef331/nimtrest/blob/master/rickles.nim#L105-L123
08:39:30FromDiscord<Phil> I'll look at it later, sick leave is over so back at work
08:39:30FromDiscord<Elegantbeef> image.png https://media.discordapp.net/attachments/371759389889003532/1185139057391587369/image.png?ex=658e85c2&is=657c10c2&hm=a0aa5c0e03de02ec89b18f68e2800081606d2afeccc7cf14fe2704ff9be07274&
08:39:32FromDiscord<Elegantbeef> Shit i lied
08:39:37FromDiscord<Elegantbeef> It took less than an hour
08:40:07FromDiscord<Elegantbeef> Hey it's 10 lines of code that's really improtant Phil
08:40:10FromDiscord<Elegantbeef> important even
08:41:26PMunchalireza0x0, I'm still not sure why you think you need async channels for this?
08:41:39PMunchThe sender just puts thing into the channel, no async required there
08:42:01PMunchThe receiver only reacts to channel messages, so it could just sleep on that read
08:42:04FromDiscord<alireza0x0> yes but for receiving from channel
08:42:22FromDiscord<alireza0x0> my threads are running the event loop, they are not allowed to
08:42:29FromDiscord<alireza0x0> wait on the cannel and stop the event loop
08:42:49PMunchAh, so you have some other work running in the second thread as well?
08:42:57FromDiscord<alireza0x0> yes ofcourse
08:43:37FromDiscord<alireza0x0> (edit) "cannel" => "channel"
08:45:12PMunchIt's not off-course for us since you haven't told us this very significant detail..
08:47:53FromDiscord<Elegantbeef> Off course are we playing golf today pmunch?!
08:48:54FromDiscord<alireza0x0> hmm i don't konw...
08:49:13FromDiscord<alireza0x0> i should just keep thinking and reading more async stuff
08:49:22FromDiscord<alireza0x0> probably i will find a way
08:50:23FromDiscord<alireza0x0> but i will finally (try to) reach to this code forexample... https://media.discordapp.net/attachments/371759389889003532/1185141772616220722/image.png?ex=658e8849&is=657c1349&hm=56e9d359b8b736f293c044a22364d1f3907b412233a45e19e58f2be358d67585&
08:52:09PMunchOf course you shouldn't play golf off course Elegantbeef
08:52:55PMunchWell you could implement a async-ish way with tryRecv and asyncSleep
08:53:13FromDiscord<alireza0x0> what im thinking right now is...
08:53:21PMunchOf course you'd get the latency, but the alternative is to have a file descriptor you can select on, and I don't think channels provide that
08:53:23FromDiscord<alireza0x0> using threadsignal (async signals)
08:53:29FromDiscord<alireza0x0> chronos provides this
08:53:48FromDiscord<alireza0x0> https://media.discordapp.net/attachments/371759389889003532/1185142655240380457/image.png?ex=658e891b&is=657c141b&hm=fe6a1d0c8f8912ed9ec7073889b3b1ff19fb88c79588af2e489cc7759419d5ef&
08:54:05FromDiscord<alireza0x0> and it has a wait function that is async
08:54:12FromDiscord<alireza0x0> and a waitsync which is not async ofcourse
08:54:37FromDiscord<alireza0x0> https://media.discordapp.net/attachments/371759389889003532/1185142861612728370/image.png?ex=658e894d&is=657c144d&hm=51a11aefae3a211216901cc5a21fa39ad566a24489a32ebd7754a4db054a30d9&
08:55:05FromDiscord<alireza0x0> in their tests, they used this between threads
08:55:39PMunchYeah that's what I described in the "alternative" above
08:55:55PMunchDidn't know Chronos provided this
08:56:14FromDiscord<alireza0x0> 👍
08:56:36PMunchBasically what you can do then is use a channel and one of these ThreadSignals
08:57:01PMunchThen wrap your send/recv in calls that signals and awaits the ThreadSignal
08:57:02FromDiscord<alireza0x0> yes, there are two ways in my mind
08:57:15FromDiscord<alireza0x0> one way is modify channel and using these instead of its thread conditions
08:57:38FromDiscord<alireza0x0> other way is add it as a bonus channel option and create a new field inside the chanenl
08:57:41FromDiscord<alireza0x0> (edit) "chanenl" => "channel"
08:57:52FromDiscord<alireza0x0> In reply to @PMunch "Then wrap your send/recv": yes exactly
09:08:33PMunchYou don't have to change channels though
09:08:37PMunchYou could just wrap it
10:06:18*PMunch quit (Remote host closed the connection)
10:25:07FromDiscord<gyatsoyt> sent a code paste, see https://play.nim-lang.org/#ix=html>
10:26:51FromDiscord<gyatsoyt> anyone?
10:28:00FromDiscord<Clonkk> From the code you're showing it seems both X & Y are increasing so it can't be a line
10:28:12FromDiscord<Clonkk> A straight line would be only X or only Y increasing
10:28:50FromDiscord<Clonkk> unless by line you mean diagonal ofc
10:29:06FromDiscord<gyatsoyt> In reply to @Clonkk "unless by line you": no not diagonal
10:29:19FromDiscord<gyatsoyt> i want it to be vertical or horizontal
10:29:30FromDiscord<gyatsoyt> which is a straight line after all
10:29:30FromDiscord<Clonkk> Yes, so only X or only Y should change
10:29:44FromDiscord<Clonkk> You are changing both
10:30:39FromDiscord<gyatsoyt> In reply to @Clonkk "You are changing both": what should i change then
10:32:33FromDiscord<Clonkk> sent a code paste, see https://play.nim-lang.org/#ix=html>
10:33:29FromDiscord<Clonkk> sent a code paste, see https://play.nim-lang.org/#ix=html>
10:34:04FromDiscord<Clonkk> Why do you need to loop over x if you already know what `toX` is ?
11:08:08*PMunch joined #nim
11:18:17FromDiscord<gyatsoyt> fixed nvm
11:23:44FromDiscord<inv2004> Hello, any nimiSlide specific chat? How is it possible to make table in it ?
11:23:53FromDiscord<inv2004> (edit) "nimiSlide" => "nimiSlides"
11:30:05*krux02 joined #nim
11:39:05FromDiscord<Phil> Nothing nimislides specific.↵This would be the correct chat for it I'd say and likely requires asking the creator (which I think is active here @hugogranstrom )
11:39:34FromDiscord<Phil> Or anyone else you can find with nimiSlides knowledge ^^
11:41:11FromDiscord<Phil> In reply to @inv2004 "Hello, any nimiSlides specific": Worst case scenario you just write raw HTML tables
11:41:14FromDiscord<Phil> https://hugogranstrom.com/nimiSlides/tutorials/inline_html.html
11:45:20FromDiscord<hugogranstrom> In reply to @inv2004 "Hello, any nimiSlides specific": @Phil correct, I'm lurking here but I easily miss stuff so if I don't answer here, open an issue in the repo with the question 😄 I don't think we have anything for tables currently but I would recommend using the markdown syntax for tables in a `nbText`
11:45:35FromDiscord<Phil> In reply to @hugogranstrom "<@180601887916163073> correct, I'm lurking": You could just open up the discussions section on your project 😛
11:46:36FromDiscord<Phil> https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/enabling-or-disabling-github-discussions-for-a-repository↵This should be the docs for it 😄
11:48:48FromDiscord<hugogranstrom> In reply to @isofruit "You could just open": Good point 👍 this should be applicable to nimib in general as well (tables)
11:49:36FromDiscord<Phil> Pretty much. Imo any project that actually garners a userbase would benefit there.↵I mostly don't have it on my stuff because none of it has an actual userbase 😄
11:49:54FromDiscord<Phil> At least none that I know of, one dude recently revealed themselves as using my lib for easy password hashing
11:50:33FromDiscord<Phil> First learned of its existence from owlkettle which uses it quite nicely
11:51:55FromDiscord<hugogranstrom> Discussions are open (I think)!
11:52:22FromDiscord<hugogranstrom> Haha yes it's always a suprise when I find out people are using my crappy code 😂
11:59:57FromDiscord<inv2004> In reply to @hugogranstrom "<@180601887916163073> correct, I'm lurking": hm, html is pretty ugly, and I would like some kind of fragmented table. I think that table could be just preformatted text
12:12:46FromDiscord<hugogranstrom> The style of HTML tables is ugly?
12:12:53FromDiscord<hugogranstrom> And what's a fragmented table?
12:20:36FromDiscord<Phil> In reply to @hugogranstrom "And what's a fragmented": They might mean what you describe as fragments in nimislides
12:20:50FromDiscord<Phil> @inv2004 would that be a correct assumption?
12:21:34FromDiscord<Phil> And by HTML you mean writing HTML or you mean the default way HTML tables look 😛 ?
12:21:57FromDiscord<inv2004> Yep, I think that I would like to make some kind of fragmented table (like we have fragmented list already) and maybe separated fragments too
12:22:05FromDiscord<Phil> The first would be a feature request to provide "table" blocks in nimislides, the second would be learning CSS 😄
12:22:28FromDiscord<inv2004> I am not sure - I see a lot of perfect presentation on youtube with it, and I even cannot find how to do it in in marp
12:22:42FromDiscord<inv2004> but I would like to use nimiSlides for it too 🙂
12:22:44FromDiscord<Phil> Okay, so by fragments you mean nimislide-fragments
12:23:52FromDiscord<Phil> In that case you could open an issue for a feature request for a table-block, though that might need to go to nimib, @hugogranstrom knows the internals there better than I do
12:25:20FromDiscord<Phil> (edit) "In that case you could open an issue for a feature request for a table-block, though that might need to go to nimib, @hugogranstrom knows the internals there ... better" added "far"
12:45:08FromDiscord<hugogranstrom> Hmm an animated table could be possible, I would have to try it out. I'm not convinced it's possible to do here though
12:45:32FromDiscord<Phil> It would be sick to be able to animate individual rows to the table
12:45:32FromDiscord<hugogranstrom> But please open an issue and link to existing presentations/videos with the effect
12:46:01FromDiscord<hugogranstrom> Yeah, it all depends on if you are allowed to wrap rows in a table in `div` or not
12:46:03FromDiscord<Phil> New row added => slide-in down/left animation for now row onto the table
12:46:10FromDiscord<Phil> (edit) "now" => "new"
12:54:38FromDiscord<hugogranstrom> Yes that would be sick
12:55:11FromDiscord<hugogranstrom> I did a very quick test in some bad online editor and it looks like it should be possible
12:55:42FromDiscord<hugogranstrom> I will give it a go in the evening 😄
13:22:28*krux02 quit (Remote host closed the connection)
13:36:36FromDiscord<inv2004> In reply to @isofruit "And by HTML you": > default way HTML tables look↵I think that both HTML or markdown tables are ok
13:36:53FromDiscord<inv2004> In reply to @isofruit "Okay, so by fragments": I have to find what is it 🙂
13:37:18FromDiscord<inv2004> the discord chat is so complicate to use. telegram is much easier
13:39:36FromDiscord<inv2004> sent a code paste, see https://play.nim-lang.org/#ix=html>
13:39:58FromDiscord<inv2004> (edit)
13:40:54FromDiscord<inv2004> also, it would be even better if you have two tables, and can switch something like: fragment table1, then table2, then table1 again - for more complicate demonstration of the data filling
13:45:49FromDiscord<inv2004> discord eats 3% cpu constantly - WTF
13:46:10FromDiscord<inv2004> (edit) "3%" => "2-3%"
13:48:04FromDiscord<Chronos [She/Her]> It used to be worse :P
13:48:42FromDiscord<Chronos [She/Her]> But it's electron, and web devs don't typically think of most stuff like memory usage, since in a browser it's not necessary to think about it if the app gets unloaded quickly anyway
13:55:18FromDiscord<inv2004> it was not the same before last update for me. vscode and discord were +- ok
14:03:11FromDiscord<Chronos [She/Her]> No idea then
14:10:50FromDiscord<hugogranstrom> In reply to @inv2004 "I would like to": The syntax would probably be on a single slide (using fragments, will send link to docs). Animating two tables at the same time though will probably not be possible unless you want to write the html yourself
14:11:53FromDiscord<hugogranstrom> https://hugogranstrom.com/nimiSlides/tutorials/fragments/basics.html
14:28:19FromDiscord<inv2004> Yep, I saw it. But not sure how to combine it with tables
14:28:40FromDiscord<inv2004> ... and if tables exist at all
14:35:06FromDiscord<hugogranstrom> I will implement it all so it isn't decided yet
14:35:18FromDiscord<hugogranstrom> But I image an API something like this:
14:36:49FromDiscord<hugogranstrom> sent a code paste, see https://play.nim-lang.org/#ix=html>
14:37:21FromDiscord<hugogranstrom> Or something like that
14:37:41FromDiscord<hugogranstrom> So it isn't currently possible yet
14:43:35FromDiscord<gcao> sent a code paste, see https://play.nim-lang.org/#ix=html>
14:44:15FromDiscord<gcao> (edit)
14:55:02*edr joined #nim
15:06:55*PMunch quit (Quit: Leaving)
15:09:53FromDiscord<michaelb.eth> In reply to @alireza0x0 "using threadsignal (async signals)": that feature was extracted from a PR for a prototype `AsyncChannel` that wasn’t merged: https://github.com/status-im/nim-chronos/pull/45↵↵might be interesting to understand better what the problems were
15:10:30FromDiscord<alireza0x0> In reply to @michaelb.eth "that feature was extracted": ahhh
15:10:38FromDiscord<alireza0x0> im wrting and teasting asyncchannel for 6 hours
15:10:56FromDiscord<alireza0x0> damn wish you told me that earieer 😭
15:11:08FromDiscord<alireza0x0> (edit) "earieer" => "earlier"
15:24:31*azimut quit (Ping timeout: 240 seconds)
15:27:50FromDiscord<gyatsoyt> sent a code paste, see https://play.nim-lang.org/#ix=html>
15:28:16FromDiscord<gyatsoyt> i have been on this problem for hours and cant find any solution online as nim is underrated
15:29:15FromDiscord<nnsee> what problem are you having
15:29:30FromDiscord<gyatsoyt> In reply to @nnsee "what problem are you": i cannot take en passant
15:29:40FromDiscord<gyatsoyt> en passant is a special pawn move
15:29:48FromDiscord<gyatsoyt> it has some conditions to play
15:29:52FromDiscord<nnsee> your problem isn't nim related?
15:30:01FromDiscord<gyatsoyt> which i cannot understand how should i add it
15:30:31FromDiscord<gyatsoyt> In reply to @nnsee "your problem isn't nim": its probably about how should i build the logic for en passant
15:30:52FromDiscord<michaelb.eth> maybe ask in #gamedev?
15:31:06FromDiscord<gyatsoyt> In reply to @michaelb.eth "maybe ask in <#706542664643772436>?": ugh ohk
15:35:22FromDiscord<michaelb.eth> In reply to @alireza0x0 "damn wish you told": sorry, didn't see your chat earlier, I'm in US Central tz so not usually awake at that time you were chatting↵↵if you do try / try to adapt the code in closed PR 45, keep in mind it wasn't written to support gc'd types, i.e. as it was written you needed to use it with e.g. `int` or a pointer to memory in the non-gc'd shared heap, else when sending across an `AsyncChannel` to another
15:36:33FromDiscord<gyatsoyt> sent a code paste, see https://play.nim-lang.org/#ix=html>
15:38:11FromDiscord<michaelb.eth> In reply to @gyatsoyt "anyone can help me": someone may see your message later today and reply; I don't know enough about chess rules to help; in the meantime maybe search web / StackOverflow / ask ChatGPT? you might need to look at a solution in a language other than Nim and then adapt what you learn to Nim
15:38:45NimEventerNew thread by aiac: SIGSEGV: Illegal storage access. (Attempt to read from nil?) in coroutines, see https://forum.nim-lang.org/t/10768
15:39:40FromDiscord<gyatsoyt> In reply to @michaelb.eth "someone may see your": well chatgpt is no good as it doesnot know that nim 2.0 exists and i couldnot find any good code on github for en passant which i coulod translate in nim
15:40:22FromDiscord<michaelb.eth> I'm sure someone will be able to help, just maybe not right away / now
15:40:42FromDiscord<gyatsoyt> In reply to @michaelb.eth "I'm sure someone will": yea i'll wait
15:43:47NimEventerNew thread by gcao: How to force inline?, see https://forum.nim-lang.org/t/10769
16:06:32*xet7 joined #nim
16:09:44*xet7 quit (Remote host closed the connection)
16:12:19FromDiscord<Phil> The last time I had to do async has been a while, did I always have to import std/asyncdispatch to use the async pragma?
16:18:35FromDiscord<Phil> I wonder what the easiest way is to figure out if a procDef is for async or not
16:21:22FromDiscord<gyatsoyt> sent a code paste, see https://play.nim-lang.org/#ix=html>
16:28:04*azimut joined #nim
16:32:21FromDiscord<alireza0x0> In reply to @michaelb.eth "sorry, didn't see your": yes, im aware of that↵Ill be using pointers to my own threadsafe object.↵Thanks alot🙏
16:59:18*mhcat joined #nim
16:59:33FromDiscord<arnetheduck> In reply to @alireza0x0 "": example of integrating chronos thread primitives with taskpools (https://github.com/status-im/nim-taskpools): https://github.com/status-im/nimbus-eth2/blob/0b9c632b6957167da7347385c1fcdfa112dd92e0/beacon_chain/gossip_processing/batch_validation.nim#L238
17:01:29FromDiscord<graveflo> sent a code paste, see https://play.nim-lang.org/#ix=html>
17:06:00FromDiscord<piqueiras> lmao .del() did me dirty...
17:09:28NimEventerNew thread by goldsteinq: Why is `enumerate()` a macro?, see https://forum.nim-lang.org/t/10770
17:17:22FromDiscord<9ih> is there a nim sequence method for finding item in a sequence by predicate?
17:17:29FromDiscord<9ih> (edit) removed "nim"
17:17:37FromDiscord<9ih> I can only find .find which finds by element
17:19:25FromDiscord<9ih> sent a code paste, see https://play.nim-lang.org/#ix=html>
17:21:27FromDiscord<gyatsoyt> In reply to @graveflo "prob gunna need more": By compiling and running and then checking if it works or not
17:22:13FromDiscord<graveflo> yea its the "checking if it works" bit that I was talking about. elaborate
17:26:33FromDiscord<hugogranstrom> @Phil @inv2004 I tried to implement the tables, but it will require a rework of the fragments parts of nimiSlides (which would be needed either way). But it doesn't look too great imo. The table lines are visible all the time. So if you have 10 row, it will show all the lines all the time and just fill in the contents of the rows each step.
17:27:07FromDiscord<Phil> It's all HTML under the hood right?
17:27:11FromDiscord<Phil> If so is this a CSS issue?
17:27:11FromDiscord<hugogranstrom> Yep
17:27:26FromDiscord<Phil> Want some CSS help?
17:27:31FromDiscord<hugogranstrom> It can be solved in multiple ways I guess
17:27:53FromDiscord<hugogranstrom> It has to play nicely with Reveal.js's functionality as well
17:27:57FromDiscord<Phil> Basically if this is because some element that implicitly gets given borders by whatever renderer is used I'm 100% certain you can have CSS rules that disable that border
17:28:29FromDiscord<hugogranstrom> I'm not sure I follow
17:29:20FromDiscord<Phil> I don't know what causes the border as I don't see the HTML/CSS that gets created. I'm wondering if one can set a CSS rule so that the border doesn't exist.↵Keep in mind I know nothing of how well one can set those CSS rules or not etc.
17:31:41FromDiscord<hugogranstrom> The code isn't terribly long if you want to play around with it https://media.discordapp.net/attachments/371759389889003532/1185272984479473766/message.txt?ex=658f027c&is=657c8d7c&hm=87312bf2dd025618ec54d85f6a6a846539a492b04406cde4d54be5f294239402&
17:31:52FromDiscord<inv2004> In reply to @hugogranstrom "<@180601887916163073> <@145220624334323712> I tried": hm
17:31:55*jkl quit (Quit: Gone.)
17:32:13om3ga[Warning] executables are still not equal <- does it means compiler not built with errors?
17:32:25FromDiscord<inv2004> (edit) "hm" => "hm, but it is not too bad. I would say it is probably even better"
17:33:49FromDiscord<hugogranstrom> In reply to @isofruit "I don't know what": It seems like it sets `border-bottom` on all but the last row of the table
17:34:07*jkl joined #nim
17:34:24FromDiscord<Phil> Let me check how to get rid of it and I will 😄
17:35:09FromDiscord<hugogranstrom> The problem is that the html is always there, it is just invisible. So I don't think the CSS can know which ones are visible and which are not
17:35:35FromDiscord<Phil> Could you make a video?↵I'm not seeing border bottoms, neither on brave nor FF
17:35:57FromDiscord<hugogranstrom> Huh, it didn't show on FF for me either but in Brave it showed
17:36:11FromDiscord<hugogranstrom> Must run it in a webserver I think
17:36:19FromDiscord<Phil> Ahhh wait there it is
17:36:22FromDiscord<Phil> Nah, wrong window for me
17:37:17FromDiscord<Phil> Okay so its a rule from black.min.css, interesting
17:37:23FromDiscord<9ih> sent a code paste, see https://play.nim-lang.org/#ix=html>
17:37:49FromDiscord<Phil> Can you add a simple `style="border:unset;"`?
17:37:58FromDiscord<Phil> To the tr elements
17:38:04FromDiscord<hugogranstrom> In reply to @isofruit "Can you add a": Oh, you want to just remove the borders?
17:38:34FromDiscord<Phil> Yeah, wont have any effect and tables without border seem alright.↵If you want to give the option you can let the user provide a bool that toggles the border on or off
17:38:58FromDiscord<Phil> Ahh wait you want to show borders, but only once the element is animated in
17:39:07FromDiscord<hugogranstrom> Okay, yes that's an option. I think borderless tables are kinda ugly though 😅
17:39:13FromDiscord<hugogranstrom> In reply to @isofruit "Ahh wait you want": exactly
17:39:15FromDiscord<hugogranstrom> ideally
17:39:38FromDiscord<hugogranstrom> but that would probably involve some javascript-amgic changing the style programatically
17:39:51FromDiscord<Phil> Now that's a curious one, in a JS framework I'd just set a timeout to apply a corresponding rule
17:40:39FromDiscord<hugogranstrom> There are callbacks that are called every time an animation is run so it is possible
17:41:29FromDiscord<hugogranstrom> It's more of a question for me if it's worth the effort at the moment or not 😛
17:42:10FromDiscord<Phil> The quick and hacky version:↵Add a style block and a CSS rule that removes the border.↵When you trigger the Animation trigger also a setTimeout function which adds a css class "border" to your element which adds a border back in.↵The css rule should be `tr.border{ border-bottom: 1px solid initial }`
17:42:15FromDiscord<Phil> Ah, fair
17:42:48FromDiscord<inventormatt> sent a code paste, see https://play.nim-lang.org/#ix=html>
17:44:27FromDiscord<9ih> works, thanks
17:44:28FromDiscord<9ih> is that safe?
17:44:37FromDiscord<hugogranstrom> In reply to @isofruit "The quick and hacky": That's helpful, I'll remember that for when I eventually pick this up again 😄 Now the fun part, you can go both forward, but also backwards in the slides and animations 😉
18:04:20FromDiscord<inventormatt> In reply to @9ih "is that safe?": I'm not certain but it's probably a bit safer than just grabbing a pointer to the array
18:10:31FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=html>
18:11:19*azimut quit (Ping timeout: 240 seconds)
18:15:01FromDiscord<griffith1deadly> sent a code paste, see https://play.nim-lang.org/#ix=html>
18:15:47FromDiscord<Phil> In reply to @griffith1deadly "why not just check": Because I'm in macro land where I am generating code and I need as part of the general code generation pipeline I need to add a discard statement for the future an async proc might return 😄
18:16:00FromDiscord<Phil> (edit) "In reply to @griffith1deadly "why not just check": Because I'm in macro land where I am generating code and I need ... as" added "this"
18:16:08FromDiscord<Phil> (edit) removed "I need this"
18:21:12FromDiscord<michaelb.eth> In reply to @isofruit "Because I'm in macro": discard or asyncCheck?↵https://nim-lang.org/docs/asyncdispatch.html#discarding-futures
18:21:52FromDiscord<Phil> Good point, asyncCheck it is
18:24:17FromDiscord<michaelb.eth> chronos has some interesting notes re: asyncCheck / asyncSpawn:↵https://github.com/status-im/nim-chronos/blob/master/chronos/internal/asyncfutures.nim#L644-L690↵not sure if or to what extent the logic there applies to std/asyncdispatch, but may be worth consideration
18:25:14FromDiscord<Phil> Fascinatingly, it appears just running poll is not that good of a move
18:25:27FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=html>
18:26:18FromDiscord<Phil> Ah, should've caught that, argh
18:26:41FromDiscord<Phil> ... is there a version of poll that doesn't raise exceptions?↵That seems like an expensive thing to have happen once a loop
18:32:00FromDiscord<Phil> I guess I could hide async behind a compiler flag so that users that don't want to use async in their procs don't have to live with the performance penalty
18:35:32FromDiscord<michaelb.eth> could it just be documented that if you opt-in to using async you shouldn't call `run()` until you've registered one/more handlers?
18:39:58FromDiscord<Phil> I don't think so, I don't see anything related to it at least
18:40:15FromDiscord<Phil> And it's not like runforever does either, that just does while true: poll
18:43:57FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=html>
18:50:06*krux02 joined #nim
18:52:21FromDiscord<michaelb.eth> can you use an `await asyncSleep …` approach in the loop?
18:56:03FromDiscord<Chronos [She/Her]> Is `func visitIdentifier[T; V: Visitor[T]](v: V, node: Identifier) = v.visitIdentifier(node)` any different from `func visitIdentifier[V: Visitor](v: V, node: Identifier) = v.visitIdentifier(node)`?
18:56:37FromDiscord<Chronos [She/Her]> Like, I need to access `T` to use as a return type, but not sure if I can just do `v.T`
18:57:10FromDiscord<Chronos [She/Her]> I can do v.T :D
18:58:14FromDiscord<Chronos [She/Her]> Usable as a return type too :)
19:00:13FromDiscord<Phil> asyncSleep?
19:00:22FromDiscord<Phil> In reply to @michaelb.eth "can you use an": asyncsleep?
19:01:33FromDiscord<michaelb.eth> was trying to think of a lightweight way to register something with std/asyncdispatch’s dispatcher
19:02:10FromDiscord<Phil> So make routeMessage async so I can await inside it, then add "await asyncSleep" at the end?
19:02:25FromDiscord<Phil> And then asyncCheck the return of routeMessage?
19:02:36FromDiscord<michaelb.eth> hmm, not quite what i had in mind
19:03:41FromDiscord<Phil> Also you sure asyncsleep isn't chronos specific?
19:03:48FromDiscord<michaelb.eth> more like, before you get to the part where you poll if you kick off an async task that loops on asyncsleep in the thread that is polling
19:04:37FromDiscord<michaelb.eth> https://nim-lang.org/docs/asyncdispatch.html#sleepAsync
19:05:07FromDiscord<Phil> Oh hey, hasPendingOperations
19:05:26FromDiscord<michaelb.eth> sorry, sleepasync not asyncsleep
19:05:38FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=html>
19:05:52FromDiscord<Phil> The if check shouldn't be tooooo bad, even if it happens once a loop
19:06:00FromDiscord<Chronos [She/Her]> In reply to @isofruit "Also you *sure* asyncsleep": `sleepAsync` in Nim iirc
19:06:38FromDiscord<michaelb.eth> In reply to @isofruit "The if check shouldn't": won’t you hot spin if there’s nothing pending?
19:06:59FromDiscord<Phil> Let me check
19:07:16FromDiscord<Phil> It didn't prior because sleep and I kinda assumed poll would do the same.... oh I see what you mean
19:07:38FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=html>
19:08:26FromDiscord<michaelb.eth> won’t that sleep block the thread from doing other stuff?
19:08:43FromDiscord<michaelb.eth> making it stutter
19:08:49FromDiscord<Phil> Yes but prevents hotspin, pretty unavoidable generally
19:09:25FromDiscord<michaelb.eth> what’s the best branch to try
19:09:44FromDiscord<Phil> From what I've seen anyway. Though I guess it should have a different config value than the value for poll
19:10:07FromDiscord<Phil> main, I don't think I'm doing anything actively on anything else
19:10:20FromDiscord<Phil> I created one for adding async support but that's only local so far as I haven't comitted anything
19:14:00FromDiscord<Phil> Like 0ms already eviscerates hotspin, 1ms drops CPU usage while idle by 99% or so
19:14:05FromDiscord<Phil> (edit) "Like 0ms ... already" added "sleep"
19:14:19FromDiscord<Phil> (edit) "Like 0ms sleep already eviscerates hotspin, 1ms drops CPU usage while idle by 99% or so ... " added "from having no sleep"
19:15:13FromDiscord<michaelb.eth> sent a code paste, see https://play.nim-lang.org/#ix=html>
19:15:41FromDiscord<michaelb.eth> then you shouldn't need, `else: sleep(data.sleepMs)`, at least that's my theory
19:15:56FromDiscord<michaelb.eth> (edit)
19:17:00FromDiscord<michaelb.eth> changed it from `100` to `1000`, shouldn't matter if it doesn't run very often (relatively speaking) just so long as there's a timer registered so `poll` doesn't raise ValueError
19:17:14FromDiscord<michaelb.eth> note: I may misunderstand the problem, for sure
19:19:52FromDiscord<Phil> I... don't claim to understand how this works.↵Does this essentially introduce latency to work on async-tasks because when idle the poll() just works on sleeping=
19:19:54FromDiscord<Phil> (edit) "sleeping=" => "sleeping?"
19:20:06FromDiscord<michaelb.eth> it should not introduce latency, no
19:20:30FromDiscord<Phil> But yeah, my issue was solely that poll was erroring, this works btw.
19:21:21FromDiscord<michaelb.eth> now, what if you remove the `data.sleepMs` argument, so just `poll()`
19:21:51FromDiscord<michaelb.eth> more as a thought exercise
19:22:05FromDiscord<Phil> It's what I'm currently doing
19:22:17FromDiscord<Phil> I'm currently on a different "problem"↵I'm flabbergasted over order of execution atm
19:22:23FromDiscord<michaelb.eth> I'm guessing that then slows the rate of checking for messages to whatever the ms vaue in sleeper is
19:22:53FromDiscord<Phil> It actually does not, server remains responsive
19:23:03FromDiscord<Phil> That's why I assumed it would affect async task execution
19:23:16FromDiscord<Phil> Because that has to make the thread sleep somewhere
19:23:27FromDiscord<michaelb.eth> no, it doesn't make it sleep 🙂
19:23:29FromDiscord<michaelb.eth> it's just a timer
19:23:47FromDiscord<Phil> Huh
19:23:59FromDiscord<Phil> So I guess we're buying into the light overhead of having a timer reset on us ever n seconds
19:24:13FromDiscord<Phil> Seems less than doing an if check 10.000x per second
19:24:31FromDiscord<michaelb.eth> sure, just so that there's something registered with the Dispatcher instance
19:24:41FromDiscord<michaelb.eth> try changing it to something large like `10.seconds`
19:24:46FromDiscord<michaelb.eth> shouldn't matter
19:27:35FromDiscord<michaelb.eth> In reply to @isofruit "I'm currently on a": I know that historically chronos made a point of scheduling callbacks in forward order while asyncdispatch scheduled them in reverse order
19:27:43FromDiscord<michaelb.eth> not sure if that's still the case
19:27:57FromDiscord<michaelb.eth> https://github.com/nim-lang/Nim/issues/7197
19:27:59FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=html>
19:29:24FromDiscord<Phil> sent a long message, see <!doctype html>
19:29:45FromDiscord<Phil> Yeah no shit the client isn't reacting to the message, I forgot that readLine is blocking the client Thread so of course that isn't reading the response
19:29:55FromDiscord<Phil> (edit) "Yeah no shit the client isn't reacting to the ... message," added "response"
19:30:35FromDiscord<Phil> ... I want a version of readLine that timeouts and lets a loop run or sth
19:31:59FromDiscord<michaelb.eth> I think you have to do readLine in another thread and connect with a stream... I've seen that before
19:32:21FromDiscord<Phil> Yeah but that's so super complicated for a minimal async example
19:33:07FromDiscord<Phil> Well actually that should be way less complicated with threadButler, just a message sending from input-reading-thread to main-thread which then sends a message to server thread and receives the response
19:33:24FromDiscord<Phil> Still not sure I like it for a minimal example
19:33:31FromDiscord<michaelb.eth> yeah, I get you
19:36:11FromDiscord<guttural666> gottem 🤣 https://media.discordapp.net/attachments/371759389889003532/1185304315871629363/image.png?ex=658f1faa&is=657caaaa&hm=1da60e1c61382977671277caeb1f68cd9075e3915a8e6cda7cc0802d7d0263cd&
19:36:20FromDiscord<Phil> Hmm couldn't I just... do the reading from within an async proc that sleeps afterwards....
19:36:33FromDiscord<Phil> That would allow demonstrating doubly asyncness - on the client AND on the server thread
19:37:17FromDiscord<michaelb.eth> async proc that does blocking readLine will block all async progress in the thread in which it's called
19:37:54FromDiscord<guttural666> async and threads? excellent
19:38:29FromDiscord<michaelb.eth> but maybe works with the client/server architecture you've got, the terminology confuses me a bit
19:39:12FromDiscord<michaelb.eth> I guess in this case you have a client doing readLine (so its own thread), and a client that (on its own seperate thread) will process the other client's message, and the server is like an event bus between them?
19:41:04FromDiscord<Phil> In reply to @guttural666 "async and threads? excellent": Async and threads seems doable, it's the "trying to be a minimal example" and "readingFromTerminal will block your shit" that is the problem 😅
19:41:26FromDiscord<Phil> In reply to @michaelb.eth "I guess in this": Kinda, I mean that still goes into triple thread setups I wanted to avoid for complexity
19:41:30FromDiscord<Phil> Was trying something way dumber
19:41:36FromDiscord<guttural666> yeet into another thread 😛
19:41:43FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=html>
19:41:57FromDiscord<Phil> (edit)
19:42:26FromDiscord<pleiad_> sent a code paste, see https://play.nim-lang.org/#ix=html>
19:42:33FromDiscord<pleiad_> (edit)
19:42:48FromDiscord<pleiad_> (edit)
19:43:43FromDiscord<pleiad_> i want to check if every assets of filesSelected's last few characters (so file extension) matches those i allowed
19:43:57FromDiscord<pleiad_> (edit)
19:44:29FromDiscord<pleiad_> so... anyone has an idea on how to check for file extensions or atleast convert it to a sequence and read the last few characters?
19:44:47FromDiscord<michaelb.eth> > compare the last 3-4 characters↵↵you might run into a problem depending on the encoding
19:45:08FromDiscord<pleiad_> i'll only use it on my pc so Windows
19:45:16FromDiscord<michaelb.eth> `char` is effectively one byte, but Nim strings are multibyte, e.g. can be UTF-8
19:45:23FromDiscord<michaelb.eth> In reply to @pleiad_ "i'll only use it": exactly
19:45:41FromDiscord<jviega> "encryption tool" == "ransomware"? 🙂
19:45:47FromDiscord<michaelb.eth> probaably
19:45:54FromDiscord<pleiad_> no
19:46:51FromDiscord<pleiad_> crime bad 😠
19:47:12FromDiscord<jviega> "These aren't the droids you're looking for"
19:47:22FromDiscord<Phil> In reply to @jviega ""These aren't the droids": No, that's beef
19:47:38FromDiscord<jviega> Heh
19:48:22FromDiscord<pleiad_> help 🙏
19:52:23FromDiscord<Phil> Aaaand bridge dead, wanted to write through the matrix client and then nothing =/
19:53:20FromDiscord<Phil> In reply to @michaelb.eth "but maybe works with": Nailed the first async example btw. User just got to compile with the threadButler logging flag to enable debug logging.↵Then BAM, you can enter stuff, send it to the server and see it arrive and being processed - But you only get responses 5s later
19:54:26FromDiscord<michaelb.eth> In reply to @pleiad_ "help 🙏": maybe try experimenting with https://nim-lang.org/docs/system.html#toOpenArrayByte%2Cstring%2Cint%2Cint
19:54:28FromDiscord<michaelb.eth> for starters
19:55:33FromDiscord<michaelb.eth> In reply to @isofruit "Nailed the first async": why 5s?
19:55:58FromDiscord<pleiad_> In reply to @michaelb.eth "maybe try experimenting with": found this on stackoverflow;↵cast[seq[char]]("string")
19:56:06FromDiscord<pleiad_> they both effectively do the same thing, right
19:56:27FromDiscord<pleiad_> (edit) "right" => "right?"
19:56:34FromDiscord<Phil> Because I added sleepAsync 5000 to the handler, the idea was demonstrating async working by allowing the user to send multiple messages (whose sending and arrival gets logged, proving that the first arriving does not block the others) before getting replies
19:56:39FromDiscord<jviega> No that doesn't work
19:56:54FromDiscord<Phil> I can't do anything with the replies on the client thread since that gets blocked by readLine but at least I can show logs
19:57:18FromDiscord<Phil> That did however raise the thought in me that async is kinda dangerous with channels
19:57:39FromDiscord<michaelb.eth> right, because reading from the channel...blocks
19:57:51FromDiscord<Phil> Because if the thread ever gets blocked by something that will immediately cause backpressure on the queue
19:58:05FromDiscord<Phil> And right now that eventually leads to dropped messages
19:58:18FromDiscord<Phil (he/him)> That actually makes me realize that async is pretty dangerous regarding messages and them potentially dropping
19:58:26FromDiscord<Phil> Bridge no longer dead
19:58:27FromDiscord<Phil (he/him)> Btw. I think I got the first async example going!↵If only by forcing the user to compile with the flag enabling threadButlers debug logging so they can see the logs stating that messages are being sent to the client↵(@michaelb.eth)
19:59:16FromDiscord<Phil> I'm not sure what one could do to avoid the backpressure problem, that seems like one of the fundamentals as I have encountered it before in microservice backends
20:00:34FromDiscord<jviega> I mean, backpressure is there for a reason
20:00:43FromDiscord<michaelb.eth> In reply to @isofruit "Because if the thread": this is why I wrote that "wish-list" thing in internals that I sent you the link to the other day, i.e. async is attractive because you don't want to worry about gumming up producer/consumer with blocking calls, but then you really need pervasive async support for that
20:01:54FromDiscord<michaelb.eth> maybe Alireza will have some luck resurrecting `AsyncChannel`
20:02:23FromDiscord<guttural666> we got two Phils here, things are getting serious
20:02:55FromDiscord<jviega> I really think async is more harmful than the goto. "blocking calls"... generally shouldn't be an issue to block on writes, it's waiting for reads from a remote that people worry about, and dispatchers that epoll() or even select() can manage it all just fine either way
20:02:55FromDiscord<michaelb.eth> there can be only one
20:03:48FromDiscord<Phil> I guess I'll call it a day with where I'm at?↵As a library developer I really can't give users of my library more than "I won't screw you over if you wanna do async"
20:04:05FromDiscord<Phil> Given I can't solve the backpressure problem that is on them I guess
20:04:17FromDiscord<michaelb.eth> In reply to @jviega "I really think async": yuck, so in a GUI we just sprinkle little sleeps everywhere?
20:04:35FromDiscord<jviega> Why sleep???
20:04:35FromDiscord<Phil> Also michaelb - send recv doesn't block though, or am I missing something?
20:04:52FromDiscord<Phil> Or rather the way I do it doesn't because I use trySend, tryRecv
20:04:56FromDiscord<jviega> Thread pools.
20:06:11FromDiscord<michaelb.eth> In reply to @jviega "Why sleep???": sure, needs more context...↵what we're looking for here is a way to have uncoordinated tasks running concurrently in different threads and we need a way to communicate back-and-forth between the threads
20:06:35FromDiscord<michaelb.eth> but we don't want to block in any of the threads while waiting for messages
20:06:47FromDiscord<michaelb.eth> async provides a paradigm for that
20:06:56FromDiscord<michaelb.eth> otherwise you have to poll..sleep..poll
20:07:00FromDiscord<Phil> which we currently do not either way
20:07:38FromDiscord<jviega> Yes, and async leads to incredibly hard to follow execution flow, that can be perfectly deterministic until you make a change in a completely unrelated component that changes the scheduling order, tickling a bug somewhere else!
20:07:40FromDiscord<Phil> At least I don't think we do, tryRecv will just return if no message is there, the only thing that blocks with it is the lock acquisition on the channel
20:07:43FromDiscord<jviega> So much worse than just using threads
20:08:02FromDiscord<jviega> You do not have to poll, sleep, poll, that's silly.
20:08:30FromDiscord<Phil> Don't you have sleep at least a little bit in a while-loop to avoid it 100%ing the CPU?
20:08:35FromDiscord<michaelb.eth> exactly
20:08:36FromDiscord<Phil> (edit) "Don't you have ... sleep" added "to"
20:08:51FromDiscord<Phil> Like 1ms already will do the trick but that's still there
20:09:24FromDiscord<michaelb.eth> eh, anyway, concurrency is complex, inherently I think
20:09:39FromDiscord<jviega> No. In a generic thread pool, there's one thread that is monitoring a shitton of fds via epoll() or kqueue(), and when one fires, it effectively fires off a worker thread
20:10:32FromDiscord<Phil> I... don't understand the mental model
20:11:16FromDiscord<jviega> And frankly, if you're not waiting for an indeterminate amount of time (like for an accept) or dealing w/ things at massive volume (like 10k connections), blocking I/O is probably for the best for most things. Keep your UI on a separate thread.
20:11:19FromDiscord<Phil> I guess that's also my problem with malebolgia, I don't "get" what to use it for other than parallelizing working through a queue of tasks
20:11:53FromDiscord<jviega> For most client-sever apps, you have a server thread that listens for connections, then when you get a connection, create a thread to handle the connection.
20:14:06FromDiscord<michaelb.eth> the context here, for what Phil what got Phil working on thread butler, is a GUI that has an online chess client running, ideally, in a background thread
20:14:23FromDiscord<michaelb.eth> and there may be other task/worker threads hanging off the main GUI thread
20:14:30FromDiscord<michaelb.eth> (edit) "Phil" => ""
20:14:36FromDiscord<michaelb.eth> (edit) removed "what "
20:15:37FromDiscord<michaelb.eth> those are long-running threads, i.e. they don't simply run a task (like "compute this expensive thing") and then shut down
20:15:41FromDiscord<Phil> Yeah you might do stuff like fetch data from a leaderboard or whatnot (as an example of an async task you may do).↵Though that one I'd likely either solve with async on the server or a "GTask" on the client
20:16:12FromDiscord<Chronos [She/Her]> I have gotten SIGILL for some reason ._.
20:16:15FromDiscord<Phil> (edit) "do).↵Though" => "do in addition to the chess engine stuff).↵Though"
20:16:41FromDiscord<jviega> Sure, and while concurrency in any form is a lot more difficult, threads still are still far less error prone than async in my experience
20:17:15FromDiscord<michaelb.eth> so the threads are listening for messages from each other, and listening to input (or for response) from e.g. the network
20:17:22FromDiscord<Phil> I am prone to agree, but I think a little bit is okay
20:17:29FromDiscord<michaelb.eth> it's not at all clear how to wire it up simply
20:17:30FromDiscord<jviega> "We're so afraid of threads, we're going to re-create them except with unfair scheduling and other problems"
20:17:51FromDiscord<michaelb.eth> well in this case, I'm talking about using them together, not one or the other
20:18:10FromDiscord<michaelb.eth> Phil may not share my enthusiasm for that combo
20:18:32FromDiscord<Phil> In reply to @jviega ""We're so afraid of": I think the idea is mostly:↵If the thread with the chess-engine on is sending an http request, do I want that to introduce latency to responses from the chess-engine (for example)
20:18:58FromDiscord<Phil> In reply to @michaelb.eth "Phil may not share": I'm of the opinion I should at least enable it.↵As a library author I should try to not limit my users choices where inappropriate
20:19:09FromDiscord<Phil> If somebody wants to footgun themselves with async - They should have the choices
20:19:10FromDiscord<Phil> (edit) "choices" => "choice"
20:19:16FromDiscord<michaelb.eth> lol
20:19:17FromDiscord<Phil> That's why I swapped from sleep to poll
20:19:19FromDiscord<jviega> What's the advantage of using both other than, there's a library I want to use that uses the one I'm not using?
20:21:41FromDiscord<michaelb.eth> let GUI be in main Thread A, with chess client running in child Thread B↵A needs to listen for user input, send messages to B, and receive messages from B↵B nees to listen for messages from the network, sends messages to A, and receive messages from A
20:22:31FromDiscord<michaelb.eth> sorry for the typos, resisting temptation to fix all of them because I now it sucks for the IRC people
20:22:53FromDiscord<Phil> I know that pain and given up for lack of self control 😅
20:23:10FromDiscord<michaelb.eth> my laptop keyboard is dying, which makes it worse of late
20:24:12FromDiscord<jviega> That's not how I'd structure any of it. But again, you can do that where, if A has no work to do, it's just epoll()ing on the fd for its remote partner, and, for instance, a pipe to communicate w the GUI thread. The GUI thread can do the same thing w/ a very short timeout if it needs to do crap if idle
20:24:15FromDiscord<Phil> I think jtvs suggestion is more:↵It's fine to have 2 long running threads that keep ping ponging, why not just create a third thread that does a blocking task (like IO) and pings a message back when done that you do stuff with then
20:24:50FromDiscord<Phil> Is my current understanding because the mental model with the monitoring thread firing up worker threads everywhere I don't understand at all
20:24:57FromDiscord<jviega> Yeah, that's more traditional, it's perfectly reasonable to more discretely break up IO tasks and have them on short-lived worker threads
20:25:13FromDiscord<jviega> You generally keep a 'pool' of available threads you can wake up whenever there's work
20:25:23FromDiscord<jviega> In the thread pooling model
20:25:37FromDiscord<Phil> Yeah, that one I can wrap my head around, basically a connection pool like for db connections (I do webdev, please forgive me 😄 )
20:26:23FromDiscord<Phil> But how to fit that into "I need to have a long running thread interact with the chess engine and keeping the state around" in a manner that doesn't suck seems difficult to me
20:27:17FromDiscord<Phil> I guess though that ideally there's also support for easy ways to do work in another thread, threadButler currently only supports setting up threads in a multiple long-running thread scenario
20:27:29FromDiscord<Phil> (edit) "I guess though that ideally there's also support for easy ways to do work in another ... thread," added "short lived"
20:28:43FromDiscord<jviega> So file descriptors are just integers that index into a list of files (sockets and everything else are all treated mostly uniformly as files). If you have something you want to write, and there might be stuff to read, you can use a call to ask the system, "which of these are available for me to use?" For writing, can they accept a message. For reading, is there data ready to read. You can also phrase it to say, "wake me up when ANY of thes
20:28:47FromDiscord<jviega> And that's just in one thread.
20:29:16FromDiscord<Phil> I guess I could provide helpers to spawn a short-lived task-thread and hand that worker-thread a pointer to the ChannelHub I have (with channels to all long-running threads) so it can message those threads with whatever
20:30:05FromDiscord<jviega> So, even w/o switching to non-blocking IO, you can quite handily in a single thread multiplex a bunch of file descriptors without ever blocking unless there's literally nothing to do
20:31:46FromDiscord<jviega> There are some minor asterisks, like when the system says, "okay, this fd is ready for write", you can only write so many bites (PIPE_BUF) before it might block, so you have to limit your write then go again. But in general, you can easily have one thread handle it's network connection and a GUI connection without spreading the connection's across extra threads, and without risking hanging the gui
20:32:11FromDiscord<jviega> And none of that requires async.
20:37:57FromDiscord<michaelb.eth> any examples of a multi-threaded desktop GUI built in that fashion? not necessarily in Nim, of course↵↵I try to keep an open mind about this kind of thing and be willing to consider different approaches; but I'm having trouble imagining what the implementation looks like
20:38:46FromDiscord<michaelb.eth> Qt has its signals/slots implementation, maybe it uses something like you're describing under the hood
20:39:18FromDiscord<jviega> I mean, they all used to be that way until fairly recently, yes.
20:39:25FromDiscord<Phil> I mean, same, mostly because webdev has drilled the entire paradigm of 2+ long running threads communicating with one another (client - server) paradigm so hard into my head that alternatives become hard to imagine
20:39:57FromDiscord<Elegantbeef> Are we at the selectors portion of this IO conversation? 😄
20:40:01FromDiscord<michaelb.eth> In reply to @isofruit "I mean, same, mostly": sure, makes sense, and for my part I'm thinking about web workers interacting with each other
20:40:12FromDiscord<michaelb.eth> In reply to @Elegantbeef "Are we at the": prolly soon
20:41:07FromDiscord<Phil> Not with me, I'm busy implementing a helper to easily spawn threads so they can do the blocking work so you can use that instead of async if you want... that is on top of async support since that wasn't so hard to provide
20:42:37FromDiscord<Elegantbeef> So did you look at the mocking code phil?!
20:42:44FromDiscord<Elegantbeef> It's been like 10 hours, you ought to have by now
20:42:55FromDiscord<Phil> Fuck no I didn't, I jumped from work straight into an idea for async
20:42:56FromDiscord<Phil> Ahhhhhh
20:43:09FromDiscord<Elegantbeef> I even named it rickles, cmon that's genius
20:43:11FromDiscord<Phil> Wait, correct punctuation is:↵Fuck. No, I didn't
20:46:13FromDiscord<Phil> Give me just a bit to think on how much I can or should limit tasks
20:47:35FromDiscord<jviega> Man, I have a task that taks < 1s w/ debug off, but 18.5 secs when debug is on. Wow.
20:48:15FromDiscord<Elegantbeef> Coincidentally I realise now this mocking API is a perfect way of exposing generic procedures as a library
20:49:14FromDiscord<Elegantbeef> Since it emits a global pointer proc it gives us something we can export, and it's automated
20:49:52FromDiscord<Phil> Hmm so you spawn a 1-off worker thread that's only going to live for like 5s for doing an HTTP call then sending a message to the main thread with the response.↵Should, or should it not, have access to the entire ChannelHub to send messages to whatever thread it pleases with however many messages, or should I limit that so I only let it fire a single message once
20:50:53FromDiscord<Phil> I guess artificially limiting options doesn't really make sense when the amount of effort for somebody to spawn their own task with such access is like 3 lines of code
20:52:07FromDiscord<graveflo> huh? Do whatever is easier or if it is a requirement that there shall only be one request and you cannot control how someone will use the single dispatch then consider adding the restriction. Otherwise why bother?
20:52:09FromDiscord<guttural666> is this de way, or is it on the same column? nimpretty doesn't even care: https://media.discordapp.net/attachments/371759389889003532/1185323434260037632/image.png?ex=658f3178&is=657cbc78&hm=06de45f0d0f786d962d60052e8098313946cc8e05bd6b83ee5ba3f15e4ab5fc2&
20:52:30FromDiscord<michaelb.eth> In reply to @guttural666 "is this de way,": you can even drop the `:` after `idx`, it's optional
20:52:52FromDiscord<Phil> No it isn't, ont with me in your code review!
20:52:57FromDiscord<Phil> (edit) "ont" => "not"
20:52:58FromDiscord<michaelb.eth> you need the `:` after the `of 0`, though
20:53:18FromDiscord<Elegantbeef> I put the case on the same column as `of`
20:53:26FromDiscord<michaelb.eth> In reply to @Elegantbeef "I put the case": the one true way
20:53:29FromDiscord<Elegantbeef> Some prefer it indented I do not see the benefit, you do you
20:53:32FromDiscord<Phil> Same
20:53:36FromDiscord<guttural666> I realized that, yeah
20:54:07FromDiscord<Phil> The main reason I do it not because of preference but because the compiler does it
20:54:27FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=html>
20:54:29FromDiscord<Phil> fuck
20:54:56FromDiscord<guttural666> kinda feel that things subordinate to some higher thing should be indented, dunno
20:55:26FromDiscord<Phil> I am proceeding to switch sides so I can declare the compiler generated case statements as wrong and bad and nobody should write it that way
20:56:56FromDiscord<graveflo> if `of` was a keyword that only had any relation to `case` statements there would be no reason to indent. Still isn't really a reason. Makes it a little weird tho
20:57:26FromDiscord<Phil> In reply to @Elegantbeef "https://github.com/beef331/nimtrest/blob/master/ric": Okay if that fully works thats nuts
20:57:32FromDiscord<guttural666> nitting hard, but I think style and reasoning about it is important, I work in a code base where everything looks like dysentery written by a hooligan and nobody cares
20:58:10FromDiscord<graveflo> that would really annoy me
20:58:51FromDiscord<michaelb.eth> In reply to @guttural666 "nitting hard, but I": lol, what lang?
20:58:53FromDiscord<guttural666> In reply to @graveflo "that would really annoy": you have your fingers on CTRL+ALT+DEL every time you look into "legacy" or BearingPoint code I swear to god
20:59:41FromDiscord<guttural666> In reply to @michaelb.eth "lol, what lang?": ABAP, it's an absolutely wild cesspool of mediocrity and carelessness
21:00:16FromDiscord<Phil> In reply to @guttural666 "ABAP, it's an absolutely": Given what I heard about ABAP, I envy your paycheck, my condolences to your mental strain
21:00:45FromDiscord<michaelb.eth> yuck
21:01:02FromDiscord<guttural666> In reply to @isofruit "Given what I heard": paycheck isn't what it used to be, but good standard SE money, but the attitude, quality control etc. in those circles is wild
21:01:22FromDiscord<guttural666> (imo)
21:01:31FromDiscord<graveflo> I stumble across these things and can't believe they exist. Even now. So corporate. Such a mistake. ugh
21:01:42FromDiscord<Phil> Doesn't it got 6 figures rather quickly?
21:01:46FromDiscord<Phil> go
21:02:28FromDiscord<Phil> That was my last info on the topic: Get good at ABAP and have fun in your sparetime because you won't at work
21:02:33FromDiscord<guttural666> nah, not in Europe at least, US is another topic, but that's capitalist dystopia where cost of living is obscene
21:02:36FromDiscord<Phil> (edit) "work" => "work, but enjoy the money"
21:03:07FromDiscord<michaelb.eth> In reply to @guttural666 "nah, not in Europe": depends a lot on where you live in the US, of course
21:03:23FromDiscord<michaelb.eth> though inflation has hit everyone/where of late, for sure
21:03:55FromDiscord<guttural666> ABAP is honestly great and I enjoy it immensly, it's a great language and very suitable for the job, pleasant to write, but the "scene" is terrible
21:04:45FromDiscord<michaelb.eth> do you work as a consultant or an internal team?
21:05:26FromDiscord<guttural666> In reply to @michaelb.eth "depends a lot on": yeah, just overgeneralizing, Europe, it's up to 70-90k € if you're 5 years in, maybe around 100-110k in some places and with seniority etc.
21:05:33FromDiscord<guttural666> internal
21:05:58FromDiscord<michaelb.eth> related question, since you mentioned a consulting firm, is it their attitute/practices re: code quality that have rubbed off on everyone else, or why is it so bad?
21:06:52FromDiscord<guttural666> sometimes it's like you presenting your consulting findings to a customer in comic sans, that's how bad even the style of the code is from third parties
21:07:14FromDiscord<Phil> What happens if I spawn a thread that eventually finishes and I just never call joinThread(that thread) ?
21:07:25FromDiscord<Phil> My own thread will definitely outlive that other thread
21:07:37FromDiscord<guttural666> style, cleanlyness etc. is the tip of the iceberg, not even talking about performance, bad practices, just bad design etc.
21:07:48FromDiscord<jviega> Sheesh, 25 years ago I made more than 90K € less than 12 months out of college, on the east coast. West coast could have done even better. Europe really doesn't pay people fairly
21:08:35FromDiscord<michaelb.eth> the worst thing I ever encountered was when I agreed to help (pro bono) a friend who had decided to go to grad school and was struggling with programming related to the lab work he and the other grad students were responsible for↵↵turned out they (and the lab director) passed all the code around in Word documents, with change tracking
21:08:40FromDiscord<guttural666> In reply to @jviega "Sheesh, 25 years ago": cost of living is way lower than say Cal, I'm considered a well paid engineer with 80k or whatever I get here
21:08:51FromDiscord<jviega> I'm talking about rural east coast.
21:08:59FromDiscord<jviega> I was not in california.
21:09:21FromDiscord<guttural666> yeah, but factor in social servives. health care, 35 hour work week
21:09:34FromDiscord<jviega> And I had no problems finding 80K starting salaries 25 years ago. Don't think a classmate did less than 60k
21:09:51FromDiscord<jviega> Factor in inflation.
21:09:55FromDiscord<michaelb.eth> what % of your income goes to taxes, or is that number after taxes
21:10:03FromDiscord<michaelb.eth> for @guttural666
21:10:21FromDiscord<Phil> Them's just bonkers numbers
21:10:24FromDiscord<jviega> I have had plenty of employees in Europe, the comp is a LOT lower than what they'd be worth in the US. Which makes it easy when I hire europeans... I pay them what they'd make in the US.
21:11:13FromDiscord<Phil> Of course I'm not in embedded, just webdev, but what I could find if I went back to 40h or so is ~70k, or at least was around the time the inflation wave hits
21:11:16FromDiscord<Phil> (edit) "hits" => "hit"
21:11:23FromDiscord<guttural666> 42% taxes, when I was living in the city of my work I was paying like 20% of my net wage for my appartment something like that
21:11:34FromDiscord<guttural666> (edit) "42% taxes, when I was living in the city of my work I was paying like 20% of my net wage ... for" added "(after taxes)"
21:12:11FromDiscord<jviega> Right and in the US the employer bears most of the the healthcare cost so net out of paycheck is generally only about 40%.
21:13:28FromDiscord<guttural666> yeah, it's a bit difficult to compare, I'd get 2800 and pay 650 for rent with 5 years on the job
21:13:47FromDiscord<guttural666> (edit) "yeah, it's a bit difficult to compare, I'd get 2800 ... and" added "(net)"
21:13:59FromDiscord<michaelb.eth> it's such a huge gulf in the US if you have to pay for your own health insurance vs. a decent plan offered by an employer; but that will start drifting into offtopic subject
21:14:06FromDiscord<guttural666> (edit) "(net)" => "(net, health and social incl.)"
21:14:23FromDiscord<guttural666> (edit) "incl.)" => "already subtracted)"
21:14:54FromDiscord<jviega> My point is you lot in europe are mainly underpaid, no need to argue against your own economic best interests there 🙂
21:14:57FromDiscord<guttural666> (edit) "yeah, it's a bit difficult to compare, I'd get 2800 (net, health and social ... already" added "incl. unemployment insurance"
21:15:29FromDiscord<graveflo> idk it sounds like the figures guttural gave would be pretty normal here in the states
21:15:33FromDiscord<Phil> I won't disagree, I just can't claim to find better, which may of course have to do with my area though I hope not with my skillset
21:15:44FromDiscord<graveflo> it would be normal to pay double that for rent and also have medial copays too
21:15:45FromDiscord<guttural666> not sure, most SE in the US don't have 35 hour work weeks and health + unemployment + other stuff included
21:15:57FromDiscord<guttural666> we just pay the state more to take care of social security
21:16:02FromDiscord<jviega> Depends on where you live.
21:16:34FromDiscord<jviega> And health is generally limited to some very small amount in tech jobs. Unemployment is a social service here.
21:16:52FromDiscord<graveflo> of course, but I'm just saying that's quite normal around where I live at least. You can get a much higher paying job but its not an out of the ordinary split
21:17:38FromDiscord<jviega> Where do you live?
21:17:55FromDiscord<graveflo> east coast near NYC, DC and Philly
21:18:22FromDiscord<guttural666> we may be way offtopic 😛
21:18:28FromDiscord<guttural666> interesting discussion tho
21:20:00FromDiscord<jviega> So I'm in NYC and grew up near DC. Last time I was hiring devs out of university, they were all getting offers of $100-$120K pretty much anywhere. Lowest I've seen in years is prob $85K. And most places you can just live in Poukeepsie if you want cheap rent 🙂
21:20:41FromDiscord<graveflo> yep thats quite typical too
21:22:52FromDiscord<guttural666> dunno, just a lot of factors to consider, I'd love to go to the US again to work there for a couple years, but not really keen on live there permanently
21:24:01FromDiscord<michaelb.eth> maybe wait a few years, see if we melt down into civil war and total chaos
21:25:01FromDiscord<guttural666> yeah, either a civil war, or I can apply to managing the IT in US atomic vaults 😛
21:25:42FromDiscord<guttural666> Kobol for the systems of a fallout vault anybody? 😛
21:26:07FromDiscord<guttural666> (edit) "Kobol" => "Cobol"
21:27:11FromDiscord<graveflo> we are really going to make that mistake again huh?
21:27:18FromDiscord<michaelb.eth> http://www.coboloncogs.org/HOME.HTM
21:29:50FromDiscord<guttural666> hahaha 😄
21:32:43*azimut joined #nim
21:33:38FromDiscord<farklenaut> quick question if I have a char what is the best/fastest way to get a string?
21:33:56FromDiscord<graveflo> `$`
21:34:23FromDiscord<farklenaut> so if I have `mystring[^1]` and I want that as a string, adding that in front will work?
21:34:31FromDiscord<graveflo> yes
21:35:27FromDiscord<farklenaut> I'm trying to parse the char as an int and I'm getting type mismatch
21:35:36FromDiscord<farklenaut> even with the $
21:35:44FromDiscord<graveflo> but you could prob also do `mystring[^1..^1]`
21:36:07FromDiscord<Elegantbeef> Ugh `{.global.}` does not make it so you can access a symbol outside of a procedure
21:36:30FromDiscord<guttural666> myint pls = mychar.parseInt() maybe?
21:36:42FromDiscord<guttural666> (edit) removed "pls"
21:36:49FromDiscord<guttural666> (edit)
21:37:01FromDiscord<graveflo> In reply to @farklenaut "I'm trying to parse": `($mystring[^1]).parseInt`
21:37:31FromDiscord<farklenaut> In reply to @guttural666 "let myint = mychar.parseInt()": type mismatch, expects string
21:38:08FromDiscord<guttural666> yeah, convert to string with $, see https://nim-lang.org/docs/strutils.html#parseInt%2Cstring
21:38:09FromDiscord<graveflo> In reply to @graveflo "`($mystring[^1]).parseInt`": `mystring[^1..^1].parseInt`↵both of these work
21:38:19FromDiscord<jviega> Well, `$s[^1]` returns a string if `s` is a string, don't know what to tell you.
21:38:35FromDiscord<graveflo> its order of operations
21:38:49FromDiscord<nixfreak> Thats is interesting↵(@michaelb.eth)
21:39:10FromDiscord<graveflo> `$mystring[^1].parseInt` -> `$(mystring[^1].parseInt)`
21:39:12FromDiscord<Elegantbeef> If it's a char you just do `(myChr.ord - '0'.ord)`
21:39:43FromDiscord<graveflo> yea that's the typical way to do it.. as in do that one LOL
21:40:40FromDiscord<michaelb.eth> In reply to @nixfreak "Thats is interesting (<@383034029135364096>)": I think that one is a joke, but it inspired a real one: COBOL on Wheelchair
21:42:24FromDiscord<michaelb.eth> https://github.com/azac/cobol-on-wheelchair/tree/master↵↵https://raw.githubusercontent.com/azac/cobol-on-wheelchair/master/images/logo.png
21:44:43FromDiscord<michaelb.eth> also, fun fact, the GnuCOBOL is one of the longest web pages you can find: https://gnucobol.sourceforge.io/faq/
21:45:01FromDiscord<michaelb.eth> (edit) "also, fun fact, the GnuCOBOL ... is" added "FAQ"
21:47:17FromDiscord<nixfreak> A computer without COBOL and Fortran is like a piece of chocolate cake without ketchup or mustard.
21:48:01FromDiscord<graveflo> I didn't know ketchup and mustard were the ingredients in the worlds most efficient cakes
21:48:18nmzwhat's wrong with fortran
21:48:31FromDiscord<nixfreak> Ruby on Rails? Don’t forget COBOL ON COGS.
21:48:56FromDiscord<guttural666> In reply to @Elegantbeef "If it's a char": chad version
21:48:58nmzI've seen fortran code in rosetta code and so on and it looks better than C
21:49:25nmzexcept when its SCREAMING CAPS code
21:49:28FromDiscord<nixfreak> Fortran is better than C
21:51:17FromDiscord<Elegantbeef> C really can go to hell
21:51:28FromDiscord<Elegantbeef> How the hell does one declare a pointer procedure based off the type of another procedure
21:51:50FromDiscord<Elegantbeef> `typeof(...) name = default;` fails cause C says "No"
21:54:57FromDiscord<Elegantbeef> Oh shit finally 😄
21:55:14FromDiscord<Elegantbeef> `typeof(proc) name = default;`
21:56:17FromDiscord<Elegantbeef> There we go Phil now rickles works everywhere
21:56:43FromDiscord<Elegantbeef> Just need a `emitAllPointerProcs` in your code to actually emit symbols before procs are declared
21:59:04FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=html>
22:00:25FromDiscord<Phil> Aww man, that sucks, I can't just make a thread for an off-hand task without running joinThread somewhere
22:00:34FromDiscord<Phil> Which will block my current thread
22:00:36FromDiscord<Phil> Dangit
22:01:02FromDiscord<Elegantbeef> I mean you can
22:01:11FromDiscord<Phil> Not without segfaults I can't
22:01:34FromDiscord<Elegantbeef> Don't let your thread outlive the data it works with
22:02:37FromDiscord<Phil> Wait it... oh right that would get collected the second the handler-proc spawning the task returns
22:03:01FromDiscord<Elegantbeef> Well if you have `ptr Container` your thread cannot outlive that scope
22:03:08FromDiscord<Elegantbeef> If so UB happens
22:03:13FromDiscord<Phil> Nah, entirely unrelated
22:03:26FromDiscord<Elegantbeef> Well I'm just assuming what you're doing forgive me
22:03:29FromDiscord<Phil> Actually, not entirely, still same project, but what's blowing up on me isn't the hub
22:03:34FromDiscord<graveflo> it's extra effort but I've never gotten away with doing anything thread related without a container that holds active threads and a message queue for the threads to at least say "hey im dying now". That way cleaning up is easier
22:03:56FromDiscord<Elegantbeef> Hey RCU doesn't need any of that! 😛
22:04:02FromDiscord<Phil> RCU?
22:04:19FromDiscord<graveflo> is that like daemon mode or something?
22:04:30FromDiscord<Elegantbeef> It's a lockfree data structure that allows mutations, but it's not very useful as it's not accurate
22:04:52FromDiscord<Phil> hmmmmmmmmmm can I just copy the data to the thread so it doesn't segfault is the question
22:05:06FromDiscord<jviega> It's not a data structure, it's a generational memory management approach for lock-free data structures
22:05:12FromDiscord<Elegantbeef> It allows multiple threads to iterate a list and thanks to the fact replacing pointers is atomic it ignores race conditions by allowing threads to operate on incorrect data
22:05:16FromDiscord<graveflo> lol pretty sure if there is no segfault to be had a segfault will not occur
22:05:40FromDiscord<Phil> Actually nevermind, it blows up even without accessing any of the data
22:05:46FromDiscord<Elegantbeef> Eh everything is a data structure to my uneducated mind
22:06:31FromDiscord<jviega> "not accurate" depends on how you build on top if it, and your idea of what accuracy means. Linearizability is the typical gold standard, and that's supportable via RCU and similar schemes
22:08:00FromDiscord<Elegantbeef> Well I'd argue that RCU explicitly implies a lack of 'accuracy' since no thread is guaranteed to iterate the fully mutated list
22:08:08FromDiscord<Elegantbeef> But sure it's up to the reader
22:08:52FromDiscord<Elegantbeef> Not saying it's not a useful thing, but it's more useful for things like process managers
22:10:13FromDiscord<Elegantbeef> Phil what are you doing now?
22:14:13FromDiscord<jviega> False
22:14:28FromDiscord<jviega> You can absolutely use schemes like that to provide 100% consistent views
22:14:44FromDiscord<graveflo> beef you say its a lock free data structure, allows mutations and "replacing pointers is atomic" but why is that special in any way? That just sounds like any other threading-unaware data structure
22:15:01FromDiscord<Phil> In reply to @Elegantbeef "Phil what are you": Trying to do async without async.↵Basically the idea is do a one-off thread that I does a thing and dies and I don't have to wait for it on my current thread to complete
22:15:03FromDiscord<Elegantbeef> It's important cause it allows you to replace next without any race conditions
22:15:05FromDiscord<jviega> I have been doing it for years, and will point you to my lock free data structures that I've pointed you to before, where you've shown no interest 🙂
22:15:34FromDiscord<Elegantbeef> I mean I do not do multi threading
22:15:38FromDiscord<graveflo> oh so its link list based and there isn't anything special about it, its just the atomic op that is exploited
22:15:43FromDiscord<jviega> No
22:15:55FromDiscord<Elegantbeef> You do not free the data that the next points to until all readers are done
22:16:13FromDiscord<Phil> Basically inspired by what jtv talked earlier about doing multitasking without async, avoiding it by just spawning it thread, letting it to the async stuff and you can remain doing your stuff
22:16:24FromDiscord<Phil> a thread
22:16:26FromDiscord<jviega> That's all the memory management schemes aim to do. You can build all sorts of lock-free data structures
22:17:00FromDiscord<Phil> Argh, not letting it do the async stuff, I mean letting it do the blocking stuff
22:17:03FromDiscord<Elegantbeef> A primitive RCU implementation is just a linked list that when you `delete` stores that into a list to be removed after the `reader`s all finish reading
22:17:06FromDiscord<graveflo> okay I think I get the idea. Pretty neat
22:17:09FromDiscord<Phil> I really should concentrate more on what I write
22:17:20FromDiscord<jviega> I've got a dictionary, set, seq / list, stack, flex-array, and ring buffer IIRC
22:17:58FromDiscord<Elegantbeef> With modern PCs it probably makes more sense to use a sequence of ints + sequence of data
22:18:24FromDiscord<jviega> Most memory allocation implementations heavily relies on linked lists for managing a free list. That's nothing unusual about rcu
22:18:38FromDiscord<graveflo> I was originally thinking of a round buffer but that just felt too boring
22:19:06FromDiscord<graveflo> too boring for a thing with a fancy name
22:19:18FromDiscord<jviega> No, I have done a lot of timing vs well optimized locking alternatives, and for those things, the lock free implementation is faster in most scenarios, primarily because there's no case where progress stalls due to something holding a lock getting context-switched out.
22:21:52FromDiscord<Elegantbeef> Now I wonder if there is any merit in auto exporting any instantiations of a generic procedure across a library....
22:22:04FromDiscord<Elegantbeef> Or if a `let x {.exportc, dynlib.} = someProc[T]` is smarter 😄
22:24:46FromDiscord<guttural666> is when used for compile time execution only, or conditional compilation of a block as well, chatGPT confused me
22:25:04FromDiscord<guttural666> trying to use when defined(prod) for conditional compilation
22:25:07FromDiscord<Elegantbeef> It's compilation dependent blocks
22:25:20FromDiscord<Elegantbeef> `when defined(...): ...` only checks the body when `defined(...)` is true
22:25:33FromDiscord<jviega> You can def think of it as a compile-time if-statement that decides what code to use
22:25:40FromDiscord<jviega> You can use 'else' and 'elif' with it
22:25:46FromDiscord<Elegantbeef> `if defined(...): ....` will always check the body but only run it if `defined(...)` is true
22:25:59FromDiscord<Elegantbeef> Can even make macros to wrap it to make it 100000% more sane 😄
22:26:22FromDiscord<Elegantbeef> https://github.com/beef331/nimtrest/blob/master/staticcases.nim#L57-L99 examples of that 😄
22:27:22FromDiscord<Elegantbeef> Do I ever wish `staticCase` and `typeCase` were builtins
22:27:34FromDiscord<guttural666> so when defined(prod): do_in_prod(), the do_in_prod() will only be compiled into my code if prod is defined
22:27:42FromDiscord<Elegantbeef> In hindsight probably `whenCase` and `whenType` is more sensible
22:27:44FromDiscord<Elegantbeef> Yes
22:27:52FromDiscord<guttural666> okay, nice
22:28:45FromDiscord<Elegantbeef> You can even do wild things like `when compiles(someExpr): someExpr` 😛
22:30:14FromDiscord<Phil> Alrighty, threadbutler supports async, tasks will have to wait, I don't get how to make it work and owlkettle already has GTask + whatever utilities I provide a skilled programmer likely could write themselves anyway so eh
22:30:34FromDiscord<graveflo> In reply to @Elegantbeef "`if defined(...): ....` will": would this just replace the `defined` call with a boolean literal?
22:30:42FromDiscord<Elegantbeef> Yes
22:30:52FromDiscord<Phil> Time to deal with my other worst enemy: docgen
22:30:54FromDiscord<Elegantbeef> Constant folding is cool
22:33:01FromDiscord<jviega> sent a long message, see <!doctype html>
22:33:20FromDiscord<jviega> On Intel, it's a bit closer to even, but lockless still wins most of the time.
22:33:41FromDiscord<jviega> And these are wait free, not just lock free, which tend to be a bit slower, but w/ firm guarantees of progress
22:34:03FromDiscord<Elegantbeef> Maybe I'm an idiot, but lockless winning is not surprising to me
22:34:16FromDiscord<Phil> This would be a lot neater if I could stop it so I could actually look at the numbers 😄
22:34:27FromDiscord<zectbumo> jtv, how do you make gifs?
22:34:40FromDiscord<Elegantbeef> Hey jtv wrote a cli program he's gotta get the money out of it
22:35:06FromDiscord<graveflo> You'd expect efficiency to go up when you make a relaxation. Just don't overcompensate ig
22:35:26FromDiscord<jviega> Oh most people assume locks are more efficient; it used to be there weren’t good approaches for lock free for most data structures
22:35:48FromDiscord<Phil> Huh, my preconception is just that lock-free is more difficult to get correct
22:35:52FromDiscord<Elegantbeef> Well waiting around for a lock generally takes time
22:35:55FromDiscord<Phil> Not necessarily that its slower
22:36:10FromDiscord<jviega> Sorry if I were at my desk not in my phone I’d convert it to 1/4 speed for you lol
22:36:12FromDiscord<Elegantbeef> Lock free should be faster cause you do not have to wait, it just requires being smarter
22:36:35FromDiscord<Phil> ~~Basically: Skill issue~~
22:36:44FromDiscord<graveflo> it's more efficient if you use sleep and make sure it's a nice long rest. no one runs smoothly when REM is interrupted
22:37:02FromDiscord<jviega> No, that’s not generally true, especially when there’s typically no contention for locks
22:37:12FromDiscord<guttural666> why web crawler is doing its first long test, so exciting 🥹
22:37:26FromDiscord<Elegantbeef> He I said I'm an idiot
22:37:33FromDiscord<Elegantbeef> Hey\
22:37:48FromDiscord<Elegantbeef> I'm also speaking in generalities of what I've done/seen
22:37:54FromDiscord<jviega> The main place there’s a clear advantage for lockless is because of context switching while holding a lock
22:38:10FromDiscord<Elegantbeef> Nim channels for instance is easy to get yourself into a lock race
22:38:29FromDiscord<Elegantbeef> Share one channel to multiple threads now you're waiting if you do `send`
22:38:40FromDiscord<guttural666> (edit) "why" => "my"
22:39:25FromDiscord<graveflo> In reply to @jviega "The main place there’s": yea this does make sense. Everyone is abuzz with context switching appeasement nowadays. It's how it works
22:39:40FromDiscord<Phil> I feel more and more validated in using `trySend` rather than `send` to avoid that scenario.
22:40:08FromDiscord<Elegantbeef> Well `trySend` either means you drop the message or wait until you can send it
22:40:21FromDiscord<jviega> I mean the great thing about lock free data structures is the progress guarantee
22:40:23FromDiscord<Phil> Yeah but it means it's the user that gets to decide if that happens or not
22:42:10FromDiscord<jviega> But those hash tables are all almost identical save for a few instructions.
22:43:38FromDiscord<jviega> Yet, you cant really deadlock w the locking one; you could if the thread died holding the lock, but the lock is never held past the library call boundary so isn’t realistically a worry
22:48:27FromDiscord<jviega> But I’m particularly tired w Nim community false claims on lockless; have even seen araq claim you can’t get consistent views which is entirely untrue.
22:49:01FromDiscord<graveflo> tangentially related to this parallel / efficient talk here, anyone know why blasting and atomic int with increments might fail after some time? I saw that issue here a couple days ago and couldn't figure it out. The memory scheme for the atomic int should have been default
22:49:48FromDiscord<Elegantbeef> > Nim community false claims on lockless↵Hey in my case it's just what I understood for RCU and not all lockless!
22:49:53FromDiscord<graveflo> idk if you can't stress them too much or something. doesn't make sense to me but I stopped looking into it after reading about the C spec
22:50:18FromDiscord<jviega> What platform and what’s the error condition??
22:51:08FromDiscord<graveflo> sent a code paste, see https://play.nim-lang.org/#ix=html>
22:51:10FromDiscord<jviega> If the compiled code is using the platform’s underlying fetch-and-add instruction it should never be non-atomic but could get memory ordering issues
22:51:15FromDiscord<Elegantbeef> Atomic operations should not suddenly stop working
22:51:23FromDiscord<graveflo> i figure but
22:51:51FromDiscord<graveflo> I had to add another 0 in there
22:51:55FromDiscord<graveflo> but then it fails
22:52:12FromDiscord<graveflo> didnt look at the codegen either
22:54:53FromDiscord<graveflo> oh and the platform is linux & ryzen 9
22:55:36FromDiscord<jviega> So I also don't know how nim's doing synchronization there. Does the parallel block not exit until any threads have exited?
22:57:46FromDiscord<graveflo> doesn't say, but it does say that it's a semantic checker so maybe it's just that. I bet you're right tho that is the simplest explanation
22:58:39FromDiscord<Elegantbeef> I too believe it blocks until all are done
22:59:18FromDiscord<graveflo> now if only fancy syntaxs like `spawn` didn't make it slightly more effort to figure out how to manipulate the underlying stuff like the thread pool
22:59:46FromDiscord<jviega> I'd be shocked if atomicInc didn't generate a FAA, so it would probably be some locking issue. It could be a memory access ordering issue if there's no barrier, but with the IO happening, seems unlikely
23:00:08FromDiscord<jviega> Which also implies some basic sync problem
23:00:31FromDiscord<jviega> Cause any synchronize primitive for end of a block like that should include a full memory barrier
23:02:56FromDiscord<Phil> Oh hey, I could just use std/tasks
23:06:38FromDiscord<graveflo> If I change it from a count to a flip flop then it is never off by more than one. It's falling off not skipping beats. Ig the `parallel` block really is the likely suspect. Ah well. To tired to care about that anymore rn
23:07:15FromDiscord<graveflo> and just like that I got an answer that was more then 1. I eat my words
23:07:24FromDiscord<guttural666> is spinning on a while loop that expensive? my cpu usage is going up to 12% when the main thread idles
23:07:55FromDiscord<guttural666> will introducing a sleep mitigate that?
23:08:05FromDiscord<Elegantbeef> You're wasting cycles
23:08:07FromDiscord<jviega> I mean, it's using CPU whenever it context switches in
23:08:40FromDiscord<jviega> If you use something the OS will queue it on (like sleep), it won't eat CPU until the OS is ready to dequeue it
23:09:13FromDiscord<jviega> This is mainly why there are things like select() and epoll(), not just plain old polling
23:09:55FromDiscord<Phil> ... is std/tasks so little used that fundamental compilation errors weren't caught?
23:09:59*xet7 joined #nim
23:10:41FromDiscord<Phil> Hmm, no I'm using it wrong somehow
23:10:54FromDiscord<guttural666> okay, so I'll have to introduce some feedback on how long another thread is likely to work, so my main thread can sleep and return ressources to the OS
23:11:27FromDiscord<guttural666> I'm also apparently memory "leaking" or accumulating
23:17:27FromDiscord<Elegantbeef> @Phil Malebolgia uses `std/tasks` so it does have some testing
23:17:39FromDiscord<Phil> I'm getting the weirdest errors
23:18:00FromDiscord<Phil> `/usr/lib/nim/std/tasks.nim(131, 30) Error: inconsistent typing for reintroduced symbol 'scratch': previous type was: ptr ScratchObj; new type is: ptr ScratchObj`What is scratch and what does it have to do with me?
23:19:11FromDiscord<Phil> I'm seeing if malebolgia behaves less weird, just wtf
23:19:21FromDiscord<graveflo> nim version?
23:19:26FromDiscord<Phil> 2.0
23:20:22FromDiscord<graveflo> so your not on devel just the regular nim release? I don't think switching to devel would help just curious
23:20:44FromDiscord<Phil> yes
23:21:00FromDiscord<Phil> The only reason I was on devel before was that there were half a dozen fixes I relied on
23:21:18FromDiscord<graveflo> and so it goes. I lot of people use devel
23:21:29FromDiscord<graveflo> (edit) "I" => "A"
23:22:40FromDiscord<Phil> Does malebolgia just block on awaitAll?
23:23:16FromDiscord<Phil> Trying to figure out whether that idea works
23:24:24FromDiscord<graveflo> looks like it
23:25:56FromDiscord<Phil> The idea really was to simply have an event-loop that can push tasks into their own thread and forget about them and the task as part of its thing either dies eventually or sends a message to another thread (which may or may not be done in a blocking manner)
23:26:17FromDiscord<Phil> And the other thread can, as part of their event loop, just read the message from their channel and do things with it
23:26:38FromDiscord<Phil> But that idea seems to not work so well because sooner or later you always start blocking for the other thread
23:27:21FromDiscord<graveflo> you never have to block for the other thread unless you are cleaning up and there are ways around that too
23:27:44FromDiscord<graveflo> in some situations you have to block but only if theres no way around that
23:27:44FromDiscord<Phil> Sure, basically every syntax variation of tasks relies on blocking eventually though
23:28:14FromDiscord<graveflo> can you not put your thread manager as a thread of it's own then?
23:29:08FromDiscord<Phil> I mean, what's the point of having a thread spawn one-off task threads when you block for the task thread in the end anyway?↵Might as well do the work on the first mentioned thread
23:29:24FromDiscord<Phil> I want fire and forget essentially
23:30:12FromDiscord<Phil> And relying on the task to either not need to return anything, or to send me a message on my channel back (or to another thread) if it does
23:30:31FromDiscord<graveflo> malebolia looks like it can easily be broken out if you want to put your main line in the event loop: https://github.com/Araq/malebolgia/blob/master/src/malebolgia.nim#L57 just would take a little patch
23:31:08FromDiscord<Phil> I'm barely at the level of using these libs, I'm not fucking around with modifying them
23:33:03FromDiscord<graveflo> I would just use the conventional thread mechanisms then, but i have 0 experience with threading in nim. It's just so far it seems that the other mechs dont have their use case centered around a custom (but simple) pool management
23:57:19*advesperacit quit ()