__await is not supported here

Hello.

I am working on Java with silver.
and compiler said await is not supported here

import java.util
import RemObjects.Elements.RTL
import RemObjects.Elements

func test() -> Task1 {
let task = Task1({
Thread.Sleep(10000)
return “Result!”
})
task.run();
return task
}

__await test() //HERE!

print(“The magic happens here.”)

What should i do?

IIRC await is not supported in main().

import java.util
import RemObjects.Elements.RTL
import RemObjects.Elements.System

func test() -> Task1<String> {
	let task = Task1<String>({
		return "Result!"
	})
	return task.run()
}

func job() -> String {
	var a = __await test().run()
	return a;
}

print("The magic happens here." + job())

No joy. for job function.

You want something like:

import java.util
import RemObjects.Elements.System

func test() -> Task1<String> {
	let task = Task1<String>({
		return "Result!"
	})
    task.Start()
	return task
}

func job() -> Task1<String> {
	var a = __await test()
	return a;
}

print("The magic happens here." + job().Result)

Note that await in the main thread, without a gui toolkit of some sort is rather pointless, since the process generally ends before anything happens. We use .Result above (which blocks) to show the process of await works.

1 Like