on_progress takes u64.
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
use crate::ast::{Expr, FnCallExpr, Ident, IdentX, ReturnType, Stmt};
|
||||
use crate::dynamic::{map_std_type_name, AccessMode, Union, Variant};
|
||||
use crate::fn_call::run_builtin_op_assignment;
|
||||
use crate::fn_native::{CallableFunction, Callback, IteratorFn, OnVarCallback};
|
||||
use crate::fn_native::{
|
||||
CallableFunction, IteratorFn, OnPrintCallback, OnProgressCallback, OnVarCallback,
|
||||
};
|
||||
use crate::module::NamespaceRef;
|
||||
use crate::optimize::OptimizationLevel;
|
||||
use crate::packages::{Package, PackagesCollection, StandardPackage};
|
||||
@@ -622,11 +624,11 @@ pub struct Engine {
|
||||
pub(crate) resolve_var: Option<OnVarCallback>,
|
||||
|
||||
/// Callback closure for implementing the `print` command.
|
||||
pub(crate) print: Callback<str, ()>,
|
||||
pub(crate) print: OnPrintCallback,
|
||||
/// Callback closure for implementing the `debug` command.
|
||||
pub(crate) debug: Callback<str, ()>,
|
||||
pub(crate) debug: OnPrintCallback,
|
||||
/// Callback closure for progress reporting.
|
||||
pub(crate) progress: Option<Callback<u64, Option<Dynamic>>>,
|
||||
pub(crate) progress: Option<OnProgressCallback>,
|
||||
|
||||
/// Optimize the AST after compilation.
|
||||
pub(crate) optimization_level: OptimizationLevel,
|
||||
@@ -2542,7 +2544,7 @@ impl Engine {
|
||||
|
||||
// Report progress - only in steps
|
||||
if let Some(progress) = &self.progress {
|
||||
if let Some(token) = progress(&state.operations) {
|
||||
if let Some(token) = progress(state.operations) {
|
||||
// Terminate script if progress returns a termination token
|
||||
return EvalAltResult::ErrorTerminated(token, Position::NONE).into();
|
||||
}
|
||||
|
@@ -1726,7 +1726,7 @@ impl Engine {
|
||||
///
|
||||
/// let mut engine = Engine::new();
|
||||
///
|
||||
/// engine.on_progress(move |&ops| {
|
||||
/// engine.on_progress(move |ops| {
|
||||
/// if ops > 10000 {
|
||||
/// Some("Over 10,000 operations!".into())
|
||||
/// } else if ops % 800 == 0 {
|
||||
@@ -1748,7 +1748,7 @@ impl Engine {
|
||||
#[inline(always)]
|
||||
pub fn on_progress(
|
||||
&mut self,
|
||||
callback: impl Fn(&u64) -> Option<Dynamic> + SendSync + 'static,
|
||||
callback: impl Fn(u64) -> Option<Dynamic> + SendSync + 'static,
|
||||
) -> &mut Self {
|
||||
self.progress = Some(Box::new(callback));
|
||||
self
|
||||
|
@@ -343,18 +343,25 @@ pub type FnPlugin = dyn PluginFunction;
|
||||
#[cfg(feature = "sync")]
|
||||
pub type FnPlugin = dyn PluginFunction + Send + Sync;
|
||||
|
||||
/// A standard callback function.
|
||||
/// A standard callback function for progress reporting.
|
||||
#[cfg(not(feature = "sync"))]
|
||||
pub type Callback<T, R> = Box<dyn Fn(&T) -> R + 'static>;
|
||||
/// A standard callback function.
|
||||
pub type OnProgressCallback = Box<dyn Fn(u64) -> Option<Dynamic> + 'static>;
|
||||
/// A standard callback function for progress reporting.
|
||||
#[cfg(feature = "sync")]
|
||||
pub type Callback<T, R> = Box<dyn Fn(&T) -> R + Send + Sync + 'static>;
|
||||
pub type OnProgressCallback = Box<dyn Fn(u64) -> Option<Dynamic> + Send + Sync + 'static>;
|
||||
|
||||
/// A standard callback function.
|
||||
/// A standard callback function for printing.
|
||||
#[cfg(not(feature = "sync"))]
|
||||
pub type OnPrintCallback = Box<dyn Fn(&str) + 'static>;
|
||||
/// A standard callback function for printing.
|
||||
#[cfg(feature = "sync")]
|
||||
pub type OnPrintCallback<T, R> = Box<dyn Fn(&str) + Send + Sync + 'static>;
|
||||
|
||||
/// A standard callback function for variable access.
|
||||
#[cfg(not(feature = "sync"))]
|
||||
pub type OnVarCallback =
|
||||
Box<dyn Fn(&str, usize, &EvalContext) -> Result<Option<Dynamic>, Box<EvalAltResult>> + 'static>;
|
||||
/// A standard callback function.
|
||||
/// A standard callback function for variable access.
|
||||
#[cfg(feature = "sync")]
|
||||
pub type OnVarCallback = Box<
|
||||
dyn Fn(&str, usize, &EvalContext) -> Result<Option<Dynamic>, Box<EvalAltResult>>
|
||||
|
Reference in New Issue
Block a user