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. 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) => void) {
while(someCondition) {
await requestValue();
// do something with value
provideResult(result);
}
}
function taskB(valueCallback: (value) => Result) {
let state = someState;
...
let handleEvent = (event) => {
let result = valueCallback(convertToValue(event));
state = updateState(result);
}
}