Created
December 25, 2024 00:45
-
-
Save stephenquan/15554eaf896b93ab56309254dd34025b to your computer and use it in GitHub Desktop.
AsyncPage.qml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AsyncPage.qml | |
import QtQuick | |
import QtQuick.Controls | |
Page { | |
function _asyncToGenerator(fn) { | |
return function() { | |
var self = this, | |
args = arguments | |
return new Promise(function(resolve, reject) { | |
var gen = fn.apply(self, args) | |
function _next(value) { | |
_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value) | |
} | |
function _throw(err) { | |
_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err) | |
} | |
_next(undefined) | |
}) | |
} | |
} | |
function _asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | |
try { | |
var info = gen[key](arg) | |
var value = info.value | |
} catch (error) { | |
reject(error) | |
return | |
} | |
if (info.done) { | |
resolve(value) | |
} else { | |
Promise.resolve(value).then(_next, _throw) | |
} | |
} | |
function pass() { | |
return new Promise(function (resolve, reject) { | |
Qt.callLater(resolve); | |
} ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment