I have some code with 2 functions. taskA
requires some value and gets that value via a callback that returns the value inside a promise. It then returns the result of doing something with that value via a second callback. taskB
provides the value via a callback that is also passed as a parameter, but this callback is synchronous.
How can I get the value from taskB
and pass it to taskA
, and get the result to pass it back to taskB
? I can modify taskA
, but taskB
must provide its value and obtain a result via a synchronous callback.
async function taskA(requestValue: () => Promise<Value>, provideResult: (result: Result) => void) {
while(someCondition) {
let value: Value = await requestValue();
let result: Result = processValue(value);
provideResult(result);
}
}
function taskB(valueCallback: (value: Value) => Result) {
let state: State = someState;
...
let handleEvent = (event) => {
let result: Result = valueCallback(convertToValue(event));
state = updateState(result);
}
}
Here's a sequence diagram of the behaviour I want to enable: