Files
endorphin-tessera-gui/examples/async-network.endor
2026-10-23 19:49:49 +08:00

26 lines
910 B
Plaintext

class TextFetcher {
output: TextBlock
problem: TextBlock
status: TextBlock
task: Object
response: String
function apply(self: TextFetcher): Unit {
self.response = self.task.result()
self.output.text = "请求完成;在 REPL 查看 fetcher.response"
}
function fetch(self: TextFetcher, url: String): Unit {
self.task = ui.fetchText(self, "request", url, self.apply)
self.response = ""
self.output.text = ""
self.status.bind("text", self.task.status)
self.problem.bind("text", self.task.error)
}
}
output = TextBlock("尚未请求网络")
problem = TextBlock("")
status = TextBlock("")
fetcher = TextFetcher(output, problem, status, ui.state(0), "")
page = Page()
page.title = "异步网络"
page.render(Column(24,16,TextBlock("在 REPL 调用 fetcher.fetch(HTTP 或 HTTPS 地址字符串)",2),status,problem,output))