My two cents

rikki cattermole rikki at cattermole.co.nz
Tue Oct 24 09:56:50 UTC 2017


On 24/10/2017 10:31 AM, Kagamin wrote:
> On Tuesday, 24 October 2017 at 07:29:08 UTC, Satoshi wrote:
>> If we want to use D for GUI development we will need this feature anyway.
> 
> To not block UI you need non-blocking IO, and async/await is not 
> required for it: vibe provides non-blocking IO with synchronous 
> interface. And here we also have another shortcoming of async/await: it 
> doesn't interact well with GUI that traditionally uses synchronous event 
> handlers (mostly because it predates async/await).

Just a random idea, something to think about:

```
struct Task {
	void delegate() del;
	void* stack;
	Status status = Status.finished;

	void continue() { del(); }
}

() {
	size_t lastJump;
	if (lastJump == J1) { lastJump=J2; jmp J2; }
	else lastJump = J1;

	J1:
	ubyte[] gotRead = doRead(__task, "...");

	yield;
	J2:

	gotRead /= 2;
	doWrite(__task, "...", gotRead);

	complete; // yield if wasn't done
}
```

From:

```
ubyte[] doRead(string name) async { ... }
void doWrite(string name, ubyte[] data) async { ... }

void callback(...) {
	ubyte[] gotRead = doRead("...");
	gotRead /= 2;
	doWrite("...", gotRead);
}
```

scope+ref+out as arguments would be a no-no.
Now if we could ditch registers usage crossing before/after yield, we 
wouldn't need to do 'patching' like fibers do.


More information about the Digitalmars-d mailing list