O'Reilly logo

D Web Development by Kai Nacke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Performing background work

Some tasks are better performed in the background than in a request-response cycle. Depending on the type of work, you can use a fiber-based task or thread.

Running a fiber-based task

A function or method that returns void can be started as a fiber-based task with the runTask() function. The parameters are the delegates (use std.functional.toDelegate() if you have a function) and possible parameters.

Note

Do not forget to be cooperative in your fiber: call a pseudo-blocking function or yield() from time to time.

You can use such a background task to collect data about the server. With the next example, you can read the /proc/loadavg file on Linux and collect the data of the last 10 minutes. On a request from a client, you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required