Skip to content

Commit 396c671

Browse files
committed
cpp constructor for Waker
1 parent 810c816 commit 396c671

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

qmetaobject/src/future.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ cpp! {{
4747
/// Reference counter.
4848
QAtomicInt refs = 0;
4949

50+
// start with refs count of 1, because caller gets the ownership.
51+
Waker(TraitObject f): future(f), refs(1) {}
52+
5053
void customEvent(QEvent *e) override {
5154
Q_UNUSED(e);
5255
woken = false;
@@ -102,10 +105,7 @@ pub fn execute_async(f: impl Future<Output = ()> + 'static) {
102105
let f = Box::into_raw(Box::new(f)) as *mut dyn Future<Output = ()>;
103106
unsafe {
104107
let waker = cpp!([f as "TraitObject"] -> *const() as "Waker*" {
105-
auto w = new Waker;
106-
w->refs++;
107-
w->future = f;
108-
return w;
108+
return new Waker(f);
109109
});
110110
poll_with_qt_waker(waker, Pin::new_unchecked(&mut *f));
111111
}

0 commit comments

Comments
 (0)