You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
Started fixing ReactNative app
This commit is contained in:
37
ReactNativeClient/lib/promise-utils.js
Normal file
37
ReactNativeClient/lib/promise-utils.js
Normal file
@ -0,0 +1,37 @@
|
||||
function promiseChain(chain, defaultValue = null) {
|
||||
let output = new Promise((resolve, reject) => { resolve(defaultValue); });
|
||||
for (let i = 0; i < chain.length; i++) {
|
||||
let f = chain[i];
|
||||
output = output.then(f);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
function promiseWhile(callback) {
|
||||
let isDone = false;
|
||||
|
||||
function done() {
|
||||
isDone = true;
|
||||
}
|
||||
|
||||
let iterationDone = false;
|
||||
let p = callback(done).then(() => {
|
||||
iterationDone = true;
|
||||
});
|
||||
|
||||
let iid = setInterval(() => {
|
||||
if (iterationDone) {
|
||||
if (isDone) {
|
||||
clearInterval(iid);
|
||||
return;
|
||||
}
|
||||
|
||||
iterationDone = false;
|
||||
callback(done).then(() => {
|
||||
iterationDone = true;
|
||||
});
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
export { promiseChain, promiseWhile }
|
Reference in New Issue
Block a user