Is www class working like a coroutine or like a Thread?

I still dont no how it works. If it is like a coroutine it means there is a time slot within each frame, where www makes a part of the Download, stops until the next Frame (yield) and continues the Download in the next frame. That also means the class has a way to determine how much time is available in each frame for the Download.

The other option is, that it works as a thread simultanusly to the Main (framebased) thread. Can anyone make that clear? Is the behaviour the same on each platform or does it work different eg. On iOS?

We simply don’t know how the whole class is implemented since it’s part of the native part of Unity. Also the implementation can be different on different platforms.

On windows it looks like the “download” is always handled / executed in a seperate thread, even local file IO. Apart from where the actual work is done, Unity will always have to synchronise the result with the main thread. This could already be done inside the isDone property, but it’s also possible that it’s handled elsewhere on the main thread.

From your question it seems you have a strange view what a coroutine is. There are no “timeslots”. You have timeslots in a multithreading environment where the OS interrupts a thread after some time to let other threads proceed their work. Cooperative multitasking has nothing to do with time, at all. If one cooperative task blocks the execution inside a loop without yielding your whole thread will be stuck there.

A “download” so using actual sockets and the http protocol is always asynchron. You can’t “stop” a download. A download is a passive process once initiated. The TCP/IP protocol stack as well as you NIC driver of the OS will handle the reception of the data. An application either uses callbacks to get informed when new data arrived or uses some sort of polling. So it checks if data is available at certain intervals.

File IO is in most operating systems a synchronous operation. So it will block until the operation is done. Of course it’s always possible to do heavy IO operations in a seperate thread to prevent the blocking of the main thread.

In general i wouldn’t recommend to use the WWW class for local file access and if you do, use a coroutine. For simple File IO it’s way easier to use the System.IO classes.

You most likely won’t get a more precise or more detailed answer on that topic, so please don’t ask the same question again. You’re using a thrid party proprietary class so you can only rely on the documentation that comes with it. The documentation on IsDone clearly says that you shouldn’t use a blocking loop. If you do it might work on some platforms but might fail on others.

The behavior is platform specific. Though the general idea is the same across all. You interact with the WWW class as though it is a coroutine. The actual implementation is in native code and uses threads.

For example, on iOS the default implementation uses Apple’s NSMutableURLRequest and NSURLConnection. The iOS implementation is in the file WWWConnection.mm in the iOS playback engine.