File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -307,3 +307,31 @@ pub fn get_capability(issuer: &Address, params: &str) -> Option<Capability> {
307307 cap. issuer == * issuer && params == cap_params
308308 } )
309309}
310+
311+ /// The `Spawn!()` macro is defined here as a no-op.
312+ /// However, in practice, `kit build` will rewrite it during pre-processing.
313+ ///
314+ /// Example:
315+ /// ```no_run
316+ /// fn init(our: Address) {
317+ /// Spawn!(|our| {
318+ /// println!("hello from {our}. I am Spawn of {}!", args["our"]);
319+ /// });
320+ /// ...
321+ /// }
322+ /// ```
323+ /// will be rewritten by `kit build` to:
324+ /// 1. Generate a new child process within the package that, here, `println!()`s,
325+ /// or, in general, executes the code given by the closure.
326+ /// 2. Replace the code lines in the parent process with [`spawn()`] to start
327+ /// the generated child and send a [`Request()`] to pass in the closure's args.
328+ /// 3. Update the relevant metadata for the package
329+ /// (i.e. `Cargo.toml`, `metadata.json`, etc.).
330+ #[ macro_export]
331+ macro_rules! Spawn {
332+ // Matches a closure with one parameter
333+ ( |$param: ident| $body: block) => { } ;
334+
335+ // If you also need to support multiple parameters in the closure:
336+ ( |$( $param: ident) ,* | $body: block) => { } ;
337+ }
You can’t perform that action at this time.
0 commit comments