我目前正在尝试使用libevent每n分钟调用一次函数/一个事件触发器,该触发器将调用该函数,并建议可以使用libevent。我可以使用它每n秒持久调用一次函数,但是无法确定如何将参数传递给它们。
#include <stdio.h>
#include <sys/time.h>
#include <event.h>
void say_hello(int fd, short event, void *arg)
{
printf("Hello\n");
// printf("%d", (int *)arg[0])
}
int main(int argc, const char* argv[])
{
struct event ev;
struct timeval tv;
tv.tv_sec = 3;
tv.tv_usec = 0;
event_init();
// event_set(&my_event, 0, EV_PERSIST, my_function, NULL);
event_set(&ev, 0, EV_PERSIST, say_hello, NULL);
// evtimer_set(&ev, say_hello, NULL);
evtimer_add(&ev, &tv);
event_dispatch();
return 0;
}
答案 0 :(得分:0)
Unexpected token, expected
已过时,请改用userA:
{
nick: cat ,
fruit: apple ,
canDance: true ,
age: 20
}
userB:
{
nick: dog ,
fruit: orange ,
canDance: false ,
age: 23
}
:
const jwtLogin = new JWTstrategy(jwtOptions, (payload, done) => {
return verifyUser(payload.username)
.then(foundUser => {
if (foundUser && new Date().getTime() / 1000 < payload.exp) {
return done(null, foundUser);
} else {
console.log(`Denied, Access token expired.`);
// <---Here I wish to hit the database and return the user's new tokens to continue...
return done(null, foundUser);
}
})
.catch(err => {
console.log(err);
return done(err, false);
});
});
最后一个参数是要传递的参数:
res
要安排执行next
中指定的事件,请使用event_set
,其原型为:
event_new