Wolfram Research

RunAfterLoading

Contributed by: Richard Hennigan (Wolfram Research)

Evaluate an expression when a package finishes loading

ResourceFunction["RunAfterLoading"][code,"context`"]

creates an event handler that evaluates code when "context`" finishes loading.

Examples

Basic Examples

Print a message when a context finishes loading:

In[1]:=
ResourceFunction["RunAfterLoading"][
 Print[Length[Names["Notation`*"]], " symbols loaded in Notation`."], "Notation`"]
Out[1]=
In[2]:=
Needs["Notation`"]

Get the load timing for a package:

In[3]:=
ResourceFunction[
ResourceObject[
Association[
   "Name" -> "RunBeforeLoading", "UUID" -> "03c8eb0d-7dba-4087-9aa2-730df19a1e32", "ResourceType" -> "Function", "Version" -> "1.0.0", "Description" -> "Evaluate an expression when a package is first \
loaded", "RepositoryLocation" -> URL[
     "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"], "WolframLanguageVersionRequired" -> "10.0", "SymbolName" -> "FunctionRepository`$\
c1ab7e5af0bc4a4e88598a0e2b5c0e7b`RunBeforeLoading", "FunctionLocation" -> CloudObject[
     "https://www.wolframcloud.com/objects/e0b613fd-5418-4287-87ad-\
e1a2f940bc8f"], "ShortName" -> "RunBeforeLoading"], {
   ResourceSystemBase -> Automatic}]][$start = Now, "NeuralNetworks`"]
Out[3]=
In[4]:=
ResourceFunction["RunAfterLoading"][$end = Now, "NeuralNetworks`"]
Out[4]=
In[5]:=
NetModel["LeNet Trained on MNIST Data"]
Out[5]=
In[6]:=
$end - $start
Out[6]=

More Examples

Scope

Retrieve the ResourceFunction:

In[7]:=
ResourceFunction["RunAfterLoading"]
Out[7]=

Retrieve the ResourceObject:

In[8]:=
ResourceObject["RunAfterLoading"]
Out[8]=

Resource History

See Also