/** * Execute the code within provided context. * This is mainly designed for context switching (e.g. in asynchronous invocation). * * @param context the context * @param f lambda to run within the context * @since 0.2.0 */ public static void runOnContext(Context context, Runnable f) { Context curContext = replaceContext(context); try { f.run(); } finally { replaceContext(curContext); } } }
/** * Execute the code within provided context. * This is mainly designed for context switching (e.g. in asynchronous invocation). * * @param context the context * @param f lambda to run within the context * @since 0.2.0 */ public static void runOnContext(Context context, Runnable f) { Context curContext = replaceContext(context); try { f.run(); } finally { replaceContext(curContext); } } }