Ad
  • Custom User Avatar
  • Custom User Avatar

    The kata design is illogical:

    	it("Should return a Promise if a Promise is yielded", () => {
    		const result = asynk(function* () {
    			yield Promise.resolve(1);
    		});
    		expect(result).toBeInstanceOf(Promise);
    	});
    	it("Should throw an error if a non-Promise is yielded", () => {
    		const result = () =>
    			asynk(function* () {
    				yield 1;
    			});
    		expect(result).toThrow();
    	});
    

    If asynk is supposed to be async, it should return a Promise and be handled in usual ways (.then/.catch). Async errors aren't thrown to the current point of execution.

    A generator returning a Promise isn't async code at all; it is a generator, not an async generator. The execution point stays the same scope, and returns to the same place when something is yielded/returned from the generator.

    So why is the generator returning Promises? Does the kata author even know how async/await and generators work?