Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator style callback does not work #325

Open
onevcat opened this issue Jan 25, 2017 · 5 comments
Open

Generator style callback does not work #325

onevcat opened this issue Jan 25, 2017 · 5 comments
Assignees

Comments

@onevcat
Copy link

onevcat commented Jan 25, 2017

Hi, 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.

@santigimeno
Copy link
Member

@onevcat I don't really know as I don't use generators myself. /cc @jonhester @tejasmanohar @albertdatui ?

@albertdatui albertdatui self-assigned this Apr 26, 2017
@ghost
Copy link

ghost commented May 13, 2017

I can confirm this doesn't work, @albertdatui are you trying to fix it?

@albertdatui
Copy link
Contributor

albertdatui commented May 13, 2017 via email

@maxym-plotnikov
Copy link

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

@JhinDeng
Copy link

you can try

let job = schedule.scheduleJob(date, function(x) {
  const a = function * () { console.log('hello world') }
  a.next()
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants