-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #765 from aiselp/dev-test
编辑器更新,添加rxjs特有调度器
- Loading branch information
Showing
16 changed files
with
468 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
let { Subscription, asyncScheduler } = require("./index.js"); | ||
const t = threads; | ||
const mainTimer = timers.mainTimer; | ||
const uiTimer = timers.uiTimer; | ||
|
||
const ioScheduler = { | ||
bid: 0, | ||
schedule(work, delay, state) { | ||
const action = new SchedulerAction(this, work); | ||
return action.schedule(state, delay); | ||
}, | ||
now() { | ||
return Date.now(); | ||
}, | ||
getexecutor() { | ||
return { | ||
id: this.bid++, | ||
th: null, | ||
run(fn, delay) { | ||
if (this.th) { | ||
this.th.setTimeout(fn, delay); | ||
} else { | ||
this.th = t.start(() => { | ||
setTimeout(fn, delay); | ||
}); | ||
} | ||
}, | ||
close() { | ||
this.th.interrupt(); | ||
this.th = null; | ||
//console.log("关闭", this.id); | ||
}, | ||
cancel() { | ||
//console.log("取消", this.id); | ||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
const SchedulerAction = function (scheduler, work) { | ||
Subscription.call(this); | ||
this.work = work; | ||
//this.subAction = []; | ||
this.executor = scheduler.getexecutor(); | ||
}; | ||
SchedulerAction.prototype = Object.create(Subscription.prototype, { | ||
constructor: { value: SchedulerAction }, | ||
}); | ||
Object.assign(SchedulerAction.prototype, { | ||
schedule(state, delay) { | ||
if (this.closed) return new Subscription(); | ||
const call = this.executor.run(() => { | ||
this.work.call(this, state); | ||
}, delay); | ||
const callAction = new Subscription(); | ||
callAction.call = call; | ||
callAction.executor = this.executor; | ||
callAction.unsubscribe = function () { | ||
this.closed = true; | ||
const cancel = this.executor.cancel; | ||
if (cancel) { | ||
cancel.call(this.executor, this.call); | ||
} | ||
}; | ||
return callAction; | ||
}, | ||
unsubscribe() { | ||
this.closed = true; | ||
this.executor.close(); | ||
}, | ||
}); | ||
|
||
const mainScheduler = { | ||
bid: 0, | ||
schedule(work, delay, state) { | ||
const action = new SchedulerAction(this, work); | ||
return action.schedule(state, delay); | ||
}, | ||
now() { | ||
return Date.now(); | ||
}, | ||
getexecutor() { | ||
return { | ||
id: null, | ||
run(fn, delay) { | ||
const id = mainTimer.setTimeout(fn, delay); | ||
return id; | ||
}, | ||
close() { | ||
//console.log("关闭"); | ||
}, | ||
cancel(id) { | ||
mainTimer.clearTimeout(id); | ||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
const uiScheduler = { | ||
bid: 0, | ||
schedule(work, delay, state) { | ||
const action = new SchedulerAction(this, work); | ||
return action.schedule(state, delay); | ||
}, | ||
now() { | ||
return Date.now(); | ||
}, | ||
getexecutor() { | ||
return { | ||
id: null, | ||
run(fn, delay) { | ||
const id = uiTimer.setTimeout(fn, delay); | ||
return id; | ||
}, | ||
close() { | ||
//console.log("关闭"); | ||
}, | ||
cancel(id) { | ||
uiTimer.clearTimeout(id); | ||
}, | ||
}; | ||
}, | ||
}; | ||
const workScheduler = { | ||
bid: 0, | ||
schedule(work, delay, state) { | ||
const action = new SchedulerAction(this, work); | ||
return action.schedule(state, delay); | ||
}, | ||
now() { | ||
return Date.now(); | ||
}, | ||
getexecutor() { | ||
return { | ||
id: null, | ||
run(fn, delay) { | ||
if (delay) { | ||
const id = uiTimer.setTimeout(() => { | ||
t.runTaskForThreadPool(fn); | ||
}, delay); | ||
return id; | ||
} else { | ||
t.runTaskForThreadPool(fn); | ||
return null; | ||
} | ||
}, | ||
close() {}, | ||
cancel(id) { | ||
if (id) uiTimer.clearTimeout(id); | ||
}, | ||
}; | ||
}, | ||
}; | ||
function newSingleScheduler() { | ||
const th = t.start(() => { | ||
setInterval(() => {}, 1000); | ||
}); | ||
th.waitFor(); | ||
return { | ||
th, | ||
bid: 0, | ||
schedule(work, delay, state) { | ||
const action = new SchedulerAction(this, work); | ||
return action.schedule(state, delay); | ||
}, | ||
now() { | ||
return Date.now(); | ||
}, | ||
getexecutor() { | ||
return { | ||
th: this.th, | ||
run(fn, delay) { | ||
return this.th.setTimeout(fn, delay); | ||
}, | ||
close() {}, | ||
cancel(id) { | ||
this.th.clearTimeout(id); | ||
}, | ||
}; | ||
}, | ||
recycle(){ | ||
this.th.interrupt() | ||
} | ||
}; | ||
} | ||
|
||
exports.ioScheduler = ioScheduler; | ||
exports.mainScheduler = mainScheduler; | ||
exports.uiScheduler = uiScheduler; | ||
exports.workScheduler = workScheduler; | ||
exports.newSingleScheduler = newSingleScheduler; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
34 changes: 34 additions & 0 deletions
34
codeeditor/src/main/java/com/aiselp/autojs/codeeditor/dialogs/LoadDialog.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.aiselp.autojs.codeeditor.dialogs | ||
|
||
import android.app.Activity | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AlertDialog | ||
import com.aiselp.autojs.codeeditor.R | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
|
||
class LoadDialog(activity: Activity) { | ||
val dialog: AlertDialog = AlertDialog.Builder( | ||
activity | ||
) | ||
.setTitle("加载中") | ||
.setView(R.layout.load) | ||
.setCancelable(false) | ||
.create() | ||
val textView: TextView by lazy { | ||
dialog.findViewById(R.id.textView)!! | ||
} | ||
|
||
init { | ||
} | ||
|
||
suspend fun setContent(text: String) { | ||
withContext(Dispatchers.Main) { | ||
textView.text = text | ||
} | ||
} | ||
|
||
fun show() { | ||
dialog.show() | ||
} | ||
} |
Oops, something went wrong.