You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because generator functions are synctactic sugar around a Generator factory, trying to wrap a generator the naive way will trigger a libWrapper exception:
game.generatorFn=function*(...args){yieldargs[0];yieldargs[1];yieldargs[2];};libWrapper.register('package_id','game.generatorFn',function*(wrapped, ...args){constgen=wrapped(...args);yieldgen.next().value+1;yieldgen.next().value+1;yieldgen.next().value+1;},"WRAPPER");console.log(game.generatorFn(1).next());// <- The wrapper for 'game.generatorFn' registered by module 'package_id' with type WRAPPER did not chain the call to the next wrapper, which breaks a libWrapper API requirement. This wrapper will be unregistered.
A workaround is to divide the wrapper into two parts, a factory, and a generator:
It might be a good idea to have libWrapper do this automatically when it detects the wrapper function is a generator. When libWrapper.register detects that the wrapper function is a generator, it should automatically create a corresponding factory, and register that instead, similar to above.
Because generator functions are synctactic sugar around a
Generator
factory, trying to wrap a generator the naive way will trigger a libWrapper exception:A workaround is to divide the wrapper into two parts, a factory, and a generator:
It might be a good idea to have libWrapper do this automatically when it detects the wrapper function is a generator. When
libWrapper.register
detects that the wrapper function is a generator, it should automatically create a corresponding factory, and register that instead, similar to above.To detect whether a function is a generator, the following StackOverflow thread is useful:
https://stackoverflow.com/questions/21559365/how-to-identify-an-es6-generator
The text was updated successfully, but these errors were encountered: