data
data copied to clipboard
draft: experimenting with primitives/types to support reactive GeneratorState
very borked, mostly a skratchpad for toying around with the types. Best I can tell there's no path to typing generator functions adequately, we'll want to compile similar to ember-concurrency.
I would update the compiler semantics though to make it more of a direct sugar overtop of generator functions. Something like this, though perhaps we can setup generator-transforms to understand a few functions whose arguments should be considered to be generators.
import { task } from '@warp-drive/experiments/task';
import { _f, _yield, _yieldX } from 'generator-transforms';
const task = createTask(_f(async function doThing() {
// not yielded
const result = await otherThing();
// yield
const state = await _yield(doStillMore());
// yield*
const moreState = await _yieldX(stuff());
}));
const task = createTask(function* doThing() {
const state1 = yield doStillMore();
const state2 = yield* stuff();
});
const task2 = createTask(async function* doAsyncThing() {
const result = await otherThing();
const state1 = yield doStillMore(result);
const state2 = yield* stuff();
});
@localResource('my-key')
class MyComponent extends Component {
@property isExpanded = false;
@signal myTask = null;
update = () => { this.myTask = myTask(); }
<template></template>
}
Related: https://github.com/microsoft/TypeScript/issues/42033