Generator style callback does not work
See original GitHub issueHi, I am new to ES6 and node-schedule. I am trying to schedule a job with a generator function as callback. I saw that #210 mentioned that generator was supported. Here is my code below:
const date = momemt().add(1, 's'); // 1 second after now.
schedule.scheduleJob('taksid', date, function*(){
console.log('Hi');
const result = yield Message.findAll();
console.log('Result: ' + result);
});
The Hi
will be printed out correctly, but the Result
will never printed out. I am using yield Message.findAll()
quite a lot in other places without problem, so I guess it might be something in the generator way of node-schedule.
I also tried to insert an yield line in the test cases of node-schedule, right before the test.ok(true);
:
var job = new schedule.Job(function*() {
yield 1; // Insert this yield statement
test.ok(true);
});
The test becomes failing too.
Since I am new to Javascript and generator, I am not sure what happened. Am I using generator correctly or did I miss something?
Thanks for any kind suggestion.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why can't the generators next function be a callback function ...
"Calling a generator function does not execute its body immediately; an iterator object for the function is returned instead.". This means that yes,...
Read more >Hanging up on Callbacks: Generators in ECMAScript 6
With generators, we can transform nested callbacks into easy-to-read top down-style code without blocking our single event loop thread.
Read more >A Study on Solving Callbacks with JavaScript Generators
Generator methods don't return a raw value, they return an object with two properties: value and done . This makes it clear when...
Read more >TensorBoard callback does not create histograms when a ...
My current workaround is to not pass a generator, but to exhaust it until I have the required number of validation samples. I...
Read more >4. Generators - You Don't Know JS: Async & Performance [Book]
(no space) form. There are arguments for both styles, but I basically prefer function *foo.. because it then matches when I reference a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi! I used Node ‘co’ module for that. let job = schedule.scheduleJob(date, function(x) { co(function* () { let variable = yield … } }.bind(null,x)) P.S. Works with AdonisJS
you can try