Threading in Sugar

From your documentation http://docs.elementscompiler.com/API/Sugar/Sugar.Threading/ it is not clear for me - what exactly Sugar support in threading.

Does it support, let’s say thread spawning, wait for thread, etc…
Or is it not work yet?

Have you checked out the source code ?

In 8.3 there is Task which supports wait for

So you will able to use it across 3 platforms.

From what I know .Net await/async happens in the same thread.

From that code, it is still not clear to me, how to work with threads.

I’m not sure what you mean. What are you trying to do ?

FWIW, proper cross-platform await support is coming in 8.3.

@mh In the Fire Beta 8.3.90.1922 the __await is missing or I need a specific library to add it as language extension? Thank you.

Define “missing”? __await should be supported on all platforms in the latest betas — but of course you need APIs that work with it, which standard (block-based) Cocoa APIs are not. We’ll start adding await-compatible APIs to Sugar, and you can of course craft your own.

Yes so basically I did not find the await compatible api in Sugar, that is what I mean.
But if this is supported (by the language), let’s say in Android, which are the API (since there are not in Cocoa already)? Thanks.

Here’s an example that shows __await working on Cocoa:

import AppKit

@IBObject public class MainWindowController : NSWindowController {

	init() {
		super.init(windowNibName: "MainWindowController")
	}

	public override func windowDidLoad() {
		super.windowDidLoad()
		updateTitle(__await GetTitleSlow())
	}
	
	func updateTitle(title: String) {
		window?.title = title
	}

	func GetTitleSlow() -> Task1<String> {
		return Task1<String>.Run() {
			usleep(1_000_000)
			dispatch_async(dispatch_get_main_queue()) {
			   self.window!.title = "not yet"
			}
			usleep(1_000_000)
			dispatch_async(dispatch_get_main_queue()) {
				self.window!.title = "still not yet"
			}
			usleep(1_000_000)
			return "That took a while!"
		}
	}

}