Constructor.
Base class for the thread worker context
Set of non-blocking methods. The user is responsible to suspend the fiber, and AsyncIO will not resume it. Instead, the callback will be called where the user can do whatever is required.
Task wrapper
Calls an user provided delegate. The delegate is called from within a separate thread and it should not do anything non-thread safe (for example, using GC must be avoided) from the runtime's perspective. Delegate receives a reference to the per-thread context which it can use.
Issues a close request, blocking the fiber connected to the provided suspendable request handler until the request finishes.
Destroys entire AsyncIO object. It's unusable after this point.
Issues a fsync request, blocking the fiber connected to the provided suspended_job until the request finishes.
Issues a pread request, blocking the fiber connected to the provided suspended_job until the request finishes.
Appends a buffer to the file.
Struct providing the initialization data for the thread.
Task wrapper
Set of non-blocking methods. The user is responsible to suspend the fiber, and AsyncIO will not resume it. Instead, the callback will be called where the user can do whatever is required.
Example showing the task-blocking API
/// Per-thread context. Can be anything, but it needs to inherit // from AsyncIO.Context class AioContext: AsyncIO.Context { int i; } // Creates the per thread context. This is executed inside // each worker thread. Useful to initialize C libraries (e.g. // curl_easy_init) // This method is synchronized, so everything here is thread safe // One must only pay attention not to call methods that need // thread-local state AsyncIO.Context makeContext() { auto ctx = new AioContext; // set some things ctx.i = 0; return ctx; } /// Callback called from another thread to set the counter void setCounter (AsyncIO.Context ctx) { // cast the per-thread context auto myctx = cast(AioContext)ctx; myctx.i++; } void example() { auto async_io = new AsyncIO(theScheduler.epoll, 10, &makeContext); // open a new file auto f = new File("var/output.txt", File.ReadWriteAppending); // write a file in another thread char[] buf = "Hello darkness, my old friend.".dup; async_io.blocking.write(buf, f.fileHandle()); // read the file from another thread buf[] = '\0'; async_io.blocking.pread(buf, f.fileHandle(), 0); test!("==")(buf[], "Hello darkness, my old friend."); test!("==")(f.length, buf.length); // call the delegate from another thread async_io.blocking.callDelegate(&setCounter); }
Class implementing AsyncIO support.