Ability of function to not be generator and then execute after return

food = ((x)=>{
   return(>) await api.fetch(x)
   api.return('plate')
})('brocolli')

Would still execute api.return()...

Sounds like generators would help, but generators are not collected by garbage collectors if there is possibility they will be used again.

There is the good ol’ setTimeout:

function foo() {

    var result = 42;
    window.setTimeout(backgroundTask, 0);
    return result;

    function backgroundTask() {
        willExecuteLater;
    }
}
try {
  return await api.fetch(x);
} finally {
  api.return('plate');
}
1 Like

@mnini What is the problem that you are trying to solve with that weird syntax? Your title is unclear, not even generator functions execute after they met their return statement. Also the description "Would still execute api.return()..." could be met by simply omitting the return(>) keyword, no?

I still thinks it's less weird and more obvious than try return finally composition.