June 28, 2015 Re: Announcing libasync, a cross-platform D event loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Sunday, 28 June 2015 at 16:57:44 UTC, Suliman wrote:
> Also next code that I take from example after run absolutely do not do nothing:
This code will register a directory watcher in the working directory, on the thread's event loop, and then use timers to create file/folder activity to trigger this directory watcher.
The only thing needed to make this work is r/w access to the working directory and a running event loop.
So, adding the line:
g_evl.run(10.seconds);
If you don't have an event loop running, your application is basically not going to receive callback events.
|
June 28, 2015 Re: Announcing libasync, a cross-platform D event loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Etienne Cimon | On Sunday, 28 June 2015 at 17:10:16 UTC, Etienne Cimon wrote: > g_evl.run(10.seconds); Hmm, sorry that would be g_evl.loop(10.seconds) or getThreadEventLoop().loop(10.seconds). I use the vibe.d driver most often. |
June 28, 2015 Re: Announcing libasync, a cross-platform D event loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Etienne Cimon | > Hmm, sorry that would be g_evl.loop(10.seconds) or getThreadEventLoop().loop(10.seconds). I use the vibe.d driver most often. I changed paths to hardcoded to prevent issue with them, but next code after run only create "hey" folder and nothing more. No files in it: { void dirWatcher() { auto g_watcher = new AsyncDirectoryWatcher(getThreadEventLoop()); g_watcher.run({ DWChangeInfo[1] change; DWChangeInfo[] changeRef = change.ptr[0..1]; while(g_watcher.readChanges(changeRef)){ writeln(change); } }); g_watcher.watchDir("."); AsyncTimer tm = new AsyncTimer(getThreadEventLoop()); tm.duration(1.seconds).run({ writeln("Creating directory ./hey"); mkdir(`D:\code\DirWathcher\hey`); assert(g_watcher.watchDir(`D:\code\DirWathcher\hey`)); tm.duration(4.seconds).run({ writeln("Writing to ./hey/tmp.tmp for the first time"); std.file.write(`D:\code\DirWathcher\hey\tmp.tmp`, "some string"); tm.duration(100.msecs).run({ writeln("Removing ./hey/tmp.tmp"); remove(`D:\code\DirWathcher\hey\tmp.tmp`); }); }); }); getThreadEventLoop().loop(10.seconds); } dirWatcher(); destroyAsyncThreads(); } -------------- And how to detect if some there was some manipulation inside monitoring folder? How I can recive name of file that was added to folder? |
June 28, 2015 Re: Announcing libasync, a cross-platform D event loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Sunday, 28 June 2015 at 18:33:28 UTC, Suliman wrote: >> Hmm, sorry that would be g_evl.loop(10.seconds) or getThreadEventLoop().loop(10.seconds). I use the vibe.d driver most often. > > I changed paths to hardcoded to prevent issue with them, but next code after run only create "hey" folder and nothing more. No files in it: Try putting the timers outside the callbacks in the meantime. I'll test it tomorrow when I'm at the office =) > > -------------- > And how to detect if some there was some manipulation inside monitoring folder? How I can recive name of file that was added to folder? There's a path in the DWFileChange change structure, you can access it with change.path. You'll have to put it in a path parser to access the filename, such as std.path |
June 28, 2015 Re: Announcing libasync, a cross-platform D event loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Etienne Cimon | > Try putting the timers outside the callbacks in the meantime. I'll test it tomorrow when I'm at the office =) Ok. Thanks. I did: dirWatcher(); getThreadEventLoop().loop(10.seconds); destroyAsyncThreads(); same result. |
June 28, 2015 Re: Announcing libasync, a cross-platform D event loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Etienne Cimon | void main() { void dirWatcher() { auto g_watcher = new AsyncDirectoryWatcher(getThreadEventLoop()); g_watcher.run({ DWChangeInfo[1] change; DWChangeInfo[] changeRef = change.ptr[0..1]; while(g_watcher.readChanges(changeRef)){ writeln(change); } }); g_watcher.watchDir("."); getThreadEventLoop(); } dirWatcher(); //destroyAsyncThreads(); } Is this code enough to monitoring folder? If I run it it's terminating, it's seems that eventloop not starting or I placed it in wrong place? |
June 28, 2015 Re: Announcing libasync, a cross-platform D event loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Sunday, 28 June 2015 at 19:34:46 UTC, Suliman wrote:
> void main()
> {
>
> void dirWatcher()
> {
> auto g_watcher = new AsyncDirectoryWatcher(getThreadEventLoop());
> g_watcher.run({
> DWChangeInfo[1] change;
> DWChangeInfo[] changeRef = change.ptr[0..1];
> while(g_watcher.readChanges(changeRef)){
> writeln(change);
> }
> });
> g_watcher.watchDir(".");
> getThreadEventLoop();
>
> }
>
> dirWatcher();
>
> //destroyAsyncThreads();
>
> }
> Is this code enough to monitoring folder?
>
> If I run it it's terminating, it's seems that eventloop not starting or I placed it in wrong place?
You should do getThreadEventLoop().loop(); and it will monitor the changes forever. Try making changes in the filesystem manually :)
|
June 29, 2015 Re: Announcing libasync, a cross-platform D event loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Etienne Cimon | Ehm, there is issue on Windows or I am again doing something wrong? void main() { void dirWatcher() { auto g_watcher = new AsyncDirectoryWatcher(getThreadEventLoop()); g_watcher.run({ DWChangeInfo[1] change; DWChangeInfo[] changeRef = change.ptr[0..1]; while(g_watcher.readChanges(changeRef)){ writeln(change); } }); g_watcher.watchDir("."); getThreadEventLoop().loop(); } dirWatcher(); destroyAsyncThreads(); } Without destroyAsyncThreads(); it's fail with exception. |
June 29, 2015 Re: Announcing libasync, a cross-platform D event loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Monday, 29 June 2015 at 20:34:11 UTC, Suliman wrote:
> Ehm, there is issue on Windows or I am again doing something wrong?
>
> void main()
> {
>
> void dirWatcher()
> {
> auto g_watcher = new AsyncDirectoryWatcher(getThreadEventLoop());
> g_watcher.run({
> DWChangeInfo[1] change;
> DWChangeInfo[] changeRef = change.ptr[0..1];
> while(g_watcher.readChanges(changeRef)){
> writeln(change);
> }
> });
> g_watcher.watchDir(".");
> getThreadEventLoop().loop();
> }
>
> dirWatcher();
>
> destroyAsyncThreads();
>
> }
>
>
> Without destroyAsyncThreads(); it's fail with exception.
Yes that line is required
|
Copyright © 1999-2021 by the D Language Foundation