Re: Background thread, async and GUI (dlangui)

2022-07-21 Thread Bagomot via Digitalmars-d-learn
On Thursday, 21 July 2022 at 17:26:07 UTC, frame wrote: The module creators want you to prevent from non-threadsafe actions. Merging into one variable can be such a non-threadsafe action, but it has not to be. For example, if you have an array of fixed length or an already allocated one and e

Re: Background thread, async and GUI (dlangui)

2022-07-21 Thread Bagomot via Digitalmars-d-learn
I had this question: how can I get the value from the `task`, like how I can get from the `spawnLinked`(`ownerTid.send` and `receive`)? I'm using a `taskPool` through `arr.parallel`, but it became necessary to collect the progress from all tasks into one variable. In this case, I can't use

Re: std.signals: Error: static assert: "Aliases to mutable thread-local data not allowed."

2022-07-21 Thread Bagomot via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 05:24:55 UTC, frame wrote: On Monday, 18 July 2022 at 10:22:16 UTC, Bagomot wrote: Why can't I do it with `std.signals`? How the to do it if I can't create static event listeners? ```d public void addEventListener(T : EventListener)(T listener) { connect(&listener

std.signals: Error: static assert: "Aliases to mutable thread-local data not allowed."

2022-07-18 Thread Bagomot via Digitalmars-d-learn
Why can't I do it with `std.signals`? How the to do it if I can't create static event listeners? ```d public void addEventListener(T : EventListener)(T listener) { connect(&listener.watch); } ```

Re: How to create Multi Producer-Single Consumer concurrency

2022-07-13 Thread Bagomot via Digitalmars-d-learn
On Wednesday, 13 July 2022 at 19:06:48 UTC, Ali Çehreli wrote: On 7/13/22 02:25, Bagomot wrote: > How to do the same with `taskPool` instead of `spawnLinked`? You are hitting the nail on the head. :) std.parallelism, which taskPool is a concept of, is for cases where operations are independen

Re: How to create Multi Producer-Single Consumer concurrency

2022-07-13 Thread Bagomot via Digitalmars-d-learn
On Tuesday, 16 June 2020 at 09:10:09 UTC, Ali Çehreli wrote: On 6/12/20 3:02 PM, adnan338 wrote: > So there are multiple "download finished" message producers, and one > consumer of those messages. Furthermore, that producer has a callback > that triggers an UI object. That's almost exactly wha

curl: byChunkAsync and onProgress

2022-07-12 Thread Bagomot via Digitalmars-d-learn
Hello everyone! How to track file download with byChunkAsync? I couldn't think of a way, and onProgress doesn't work for obvious reasons. Any ideas other than writing an analogue of byChunkAsync (I looked at the source code and realized that I couldn't do it)?

Re: Background thread, async and GUI (dlangui)

2022-07-12 Thread Bagomot via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 19:25:42 UTC, Ali Çehreli wrote: On 7/12/22 11:47, Bagomot wrote: > I now have a couple more questions about `Task`: > 1) How to run a non-static class method through `task`? > 2) How to use `taskPool` to run a series of tasks of the same type (from > question 1)? As

Re: Background thread, async and GUI (dlangui)

2022-07-12 Thread Bagomot via Digitalmars-d-learn
On Monday, 11 July 2022 at 09:32:46 UTC, evilrat wrote: curl.onProgress = delegate int(size_t dltotal, size_t dlnow, size_t ultotal, size_t ulnow) { // even though onProgress can be run in another thread this delegate will be run on next UI tick executeInUiThread( (){ progressBar.s

Re: Background thread, async and GUI (dlangui)

2022-07-10 Thread Bagomot via Digitalmars-d-learn
Based on Thread, I managed to do what I intended. I have not yet been able to figure out how to do the same through the Task. Here in the example, when you click on the Start button, a worker is launched that updates the progress bar. ```d import dlangui; import core.thread; import std.conv;

Re: Background thread, async and GUI (dlangui)

2022-07-09 Thread Bagomot via Digitalmars-d-learn
On Friday, 8 July 2022 at 21:47:32 UTC, Ali Çehreli wrote: Aside: What does the return value 'true' mean? Docs says: Handler of click signal should return true if signal is processed. I am not sure whether my explicit way of starting a thread (albeit with std.parallelism) is the right way h

Re: Background thread, async and GUI (dlangui)

2022-07-08 Thread Bagomot via Digitalmars-d-learn
On Friday, 8 July 2022 at 08:04:45 UTC, Bagomot wrote: On Thursday, 7 July 2022 at 18:26:15 UTC, Ali Çehreli wrote: Summing up your help and GrimMaple, I understood how to make the file download progress bar beautifully. Thank you! I only have a question with how I can work with the GUI from

Re: Background thread, async and GUI (dlangui)

2022-07-08 Thread Bagomot via Digitalmars-d-learn
On Thursday, 7 July 2022 at 18:26:15 UTC, Ali Çehreli wrote: Summing up your help and GrimMaple, I understood how to make the file download progress bar beautifully. Thank you! I only have a question with how I can work with the GUI from other threads. For example, in my application I have a

Background thread, async and GUI (dlangui)

2022-07-06 Thread Bagomot via Digitalmars-d-learn
Hello! I have a few questions about multithreading, asynchrony and how it works with the GUI. 1) How to make asynchronous HTTP requests with curl in order to receive progress and status? And how do you know that the request is completed? This question is related to the next one, so it should

Re: Starting and managing threads

2022-01-16 Thread Bagomot via Digitalmars-d-learn
The program does nothing probably because of that continue. (?) No, it does work inside the loop. So, the event loop is in a separate thread. What should happen when the events trigger? Do you want this thread to handle the events or should this thread send a > message to the main thread (or

Re: Starting and managing threads

2022-01-15 Thread Bagomot via Digitalmars-d-learn
On Saturday, 15 January 2022 at 19:07:20 UTC, frame wrote: On Wednesday, 12 January 2022 at 08:50:09 UTC, Bagomot wrote: Why? What am I doing wrong? I guess your main() exits and just ends all threads? No, the program continues to run. And I tested it with while in main.

Re: Starting and managing threads

2022-01-15 Thread Bagomot via Digitalmars-d-learn
On Wednesday, 12 January 2022 at 08:50:09 UTC, Bagomot wrote: Good day! I keep giving rise to problems. Above, Tejas helped me a lot, but still doesn't work. I gave up using the fswatch library, thinking that the problem was in it. Now trying to do it using libasync. Here is the code that runs

Re: Starting and managing threads

2022-01-12 Thread Bagomot via Digitalmars-d-learn
Good day! I keep giving rise to problems. Above, Tejas helped me a lot, but still doesn't work. I gave up using the fswatch library, thinking that the problem was in it. Now trying to do it using libasync. Here is the code that runs on the main thread, it blocks further actions on that thread.

Re: Starting and managing threads

2021-12-28 Thread Bagomot via Digitalmars-d-learn
Thanks! It works. Perhaps there will still be difficulties, I will write here.

Re: Starting and managing threads

2021-12-28 Thread Bagomot via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 15:42:04 UTC, Tejas wrote: On Tuesday, 28 December 2021 at 14:19:46 UTC, Bagomot wrote: On Monday, 27 December 2021 at 10:59:07 UTC, Ali Çehreli wrote: On 12/27/21 1:33 AM, Bagomot wrote: > separate thread, without blocking the main one. I think you can use std

Re: Starting and managing threads

2021-12-28 Thread Bagomot via Digitalmars-d-learn
On Monday, 27 December 2021 at 10:59:07 UTC, Ali Çehreli wrote: On 12/27/21 1:33 AM, Bagomot wrote: > separate thread, without blocking the main one. I think you can use std.concurrency there. I have a chapter here: http://ddili.org/ders/d.en/concurrency.html Look for 'struct Exit' to see

Starting and managing threads

2021-12-27 Thread Bagomot via Digitalmars-d-learn
Hello everybody! My program uses the fswatch library to track changes in a directory. It runs on the main thread of the program. I need it to do its work in a separate thread, without blocking the main one. In addition, I need to be able to terminate the thread at the moment I want from the m

Re: Running only one instance of the app

2021-12-02 Thread Bagomot via Digitalmars-d-learn
On Thursday, 2 December 2021 at 13:28:12 UTC, Steven Schveighoffer wrote: On 12/2/21 7:05 AM, Bagomot wrote: This works for Windows. I need something similar for Linux and Macos. Tell me how, if you know. Maybe the standard library D already has the required functionality? Or are there bette

Running only one instance of the app

2021-12-02 Thread Bagomot via Digitalmars-d-learn
Hello everyone! I need to allow only one instance of my application to run. I use this way for Windows: ```d import std.stdio; import std.utf; version(Windows) { import core.sys.windows.winbase; import core.sys.windows.windows; } void main(string[] args) { string mutexN

Re: How to parse a json node that contains children of different types?

2021-07-20 Thread Bagomot via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 03:00:51 UTC, Mathias LANG wrote: TL;DR: If you want to use loosely typed data in a strongly typed language, you need to come up with a common type. That common type is usually either a discriminated union (which a JSON object is, essentially) or something that is

How to parse a json node that contains children of different types?

2021-07-20 Thread Bagomot via Digitalmars-d-learn
I have a json like this: ```json { "arguments":{ "jvm":[ { "rules":[ { "action":"allow", "os":{ "name":"osx" } } ], "value":[