Ad
  • Custom User Avatar

    Can I get these issues resolved, perhaps?

  • Custom User Avatar

    Tests should be a little more logical now

  • Custom User Avatar

    Random tests added

  • Custom User Avatar

    Aha, I get you! Thank you for laying it out. I can't think of a way to test that an error is not thrown in place while simultaneously handling the unhandled rejection. The best I could come up with is Should handle thrown errors as rejections where it tests that an error thrown in the generator is turned into a rejection.

    Luckily, I can get a passing test for Should not throw in place and Codewars doesn't much care about unhandled rejections.
    I've also randomised much of the data in the test fixture.

    As for async generators, I specifically wanted to emulate async/await with plain old generators. I should emphasise that in the description!
    I could perhaps still do a better job of explaining in description; is there anything else I'm missing?

    Thanks a lot for your assistance on my first kata.

    EDIT: Oh I just thought of some nicer ways to randomise that would help prevent some of the brute forcing. Will update shortly.

  • Custom User Avatar

    Hello, yes asynk is supposed to return a Promise whether the last yielded/returned value from the generator is a Promise or not. The generator yields Promises to the asynk function. You're right it's not an async generator, it's just a generator.

    The generator can return a Promise too, just like async functions can return a Promise. Or they can return values which are wrapped in Promises. Both of these async functions returns a Promise of 1:

    async function hello1() {
    	return 1;
    }
    async function hello2() {
    	return Promise.resolve(1);
    }
    

    I want to highlight that the yields shouldn't be returned from asynk. Both of these should give you a Promise of undefined:

    const y = async () => {
    	await Promise.resolve(1);
    };
    
    y().then(console.log);
    
    const x = asynk(function* () {
    	yield Promise.resolve(1);
    });
    
    x.then(console.log);
    

    I will, however, update the tests to be more logical, and since async functions allow you to await a non-Promise for some reason, perhaps I should allow that too?

    Please give me some pointers, as I'm new to writing tests.