Skip to content

Commit 920f1c8

Browse files
Replace references to Invoke and InvokeExport with InvokeAsync and InvokeExportAsync throughout docs
1 parent 4b38519 commit 920f1c8

File tree

1 file changed

+16
-16
lines changed
  • src/Microsoft.AspNetCore.NodeServices

1 file changed

+16
-16
lines changed

src/Microsoft.AspNetCore.NodeServices/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class SomeController : Controller
7676
{
7777
_nodeServices = nodeServices;
7878
}
79-
79+
8080
// ... your action methods are here ...
8181
}
8282
```
@@ -86,7 +86,7 @@ Then you can use this instance to make calls into Node.js code, e.g.:
8686
```csharp
8787
public async Task<IActionResult> MyAction()
8888
{
89-
var result = await _nodeServices.Invoke<int>("./addNumbers", 1, 2);
89+
var result = await _nodeServices.InvokeAsync<int>("./addNumbers", 1, 2);
9090
return Content("1 + 2 = " + result);
9191
}
9292
```
@@ -102,7 +102,7 @@ module.exports = function (callback, first, second) {
102102

103103
As you can see, the exported JavaScript function will receive the arguments you pass from .NET (as long as they are JSON-serializable), along with a Node-style callback you can use to send back a result or error when you are ready.
104104

105-
When the `Invoke<T>` method receives the result back from Node, the result will be JSON-deserialized to whatever generic type you specified when calling `Invoke<T>` (e.g., above, that type is `int`). If `Invoke<T>` receives an error from your Node code, it will throw an exception describing that error.
105+
When the `InvokeAsync<T>` method receives the result back from Node, the result will be JSON-deserialized to whatever generic type you specified when calling `InvokeAsync<T>` (e.g., above, that type is `int`). If `InvokeAsync<T>` receives an error from your Node code, it will throw an exception describing that error.
106106

107107
If you want to put `addNumber.js` inside a subfolder rather than the root of your app, then also amend the path in the `_nodeServices.Invoke` call to match that path.
108108

@@ -116,9 +116,9 @@ In other types of .NET app where you don't have ASP.NET Core's DI system, you ca
116116
var nodeServices = Configuration.CreateNodeServices(new NodeServicesOptions());
117117
```
118118

119-
Besides this, the usage is the same as described for ASP.NET above, so you can now call `nodeServices.Invoke<T>(...)` etc.
119+
Besides this, the usage is the same as described for ASP.NET above, so you can now call `nodeServices.InvokeAsync<T>(...)` etc.
120120

121-
You can dispose the `nodeServices` object whenever you are done with it (and it will shut down the associated Node.js instance), but because these instances are expensive to create, you should whenever possible retain and reuse instances. They are thread-safe - you can call `Invoke<T>` simultaneously from multiple threads. Also, `NodeServices` instances are smart enough to detect if the associated Node instance has died and will automatically start a new Node instance if needed.
121+
You can dispose the `nodeServices` object whenever you are done with it (and it will shut down the associated Node.js instance), but because these instances are expensive to create, you should whenever possible retain and reuse instances. They are thread-safe - you can call `InvokeAsync<T>` simultaneously from multiple threads. Also, `NodeServices` instances are smart enough to detect if the associated Node instance has died and will automatically start a new Node instance if needed.
122122

123123

124124
# API Reference
@@ -197,25 +197,25 @@ var nodeServices = Configuration.CreateNodeServices(new NodeServicesOptions {
197197
* `HostingModel` - an `NodeHostingModel` enum value. See: [hosting models](#hosting-models)
198198
* `ProjectPath` - if specified, controls the working directory used when launching Node instances. This affects, for example, the location that `require` statements resolve relative paths against. If not specified, your application root directory is used.
199199
* `WatchFileExtensions` - if specified, the launched Node instance will watch for changes to any files with these extension, and auto-restarts when any are changed.
200-
200+
201201
**Return type:** `NodeServices`
202202

203-
If you create a `NodeServices` instance this way, you can also dispose it (call `nodeServiceInstance.Dispose();`) and it will shut down the associated Node instance. But because these instances are expensive to create, you should whenever possible retain and reuse your `NodeServices` object. They are thread-safe - you can call `nodeServiceInstance.Invoke<T>(...)` simultaneously from multiple threads.
203+
If you create a `NodeServices` instance this way, you can also dispose it (call `nodeServiceInstance.Dispose();`) and it will shut down the associated Node instance. But because these instances are expensive to create, you should whenever possible retain and reuse your `NodeServices` object. They are thread-safe - you can call `nodeServiceInstance.InvokeAsync<T>(...)` simultaneously from multiple threads.
204204

205205
### Invoke&lt;T&gt;
206206

207207
**Signature:**
208208

209209
```csharp
210-
Invoke<T>(string moduleName, params object[] args)
210+
InvokeAsync<T>(string moduleName, params object[] args)
211211
```
212212

213213
Asynchronously calls a JavaScript function and returns the result, or throws an exception if the result was an error.
214214

215215
**Example 1: Getting a JSON-serializable object from Node (the most common use case)**
216216

217217
```csharp
218-
var result = await myNodeServicesInstance.Invoke<TranspilerResult>(
218+
var result = await myNodeServicesInstance.InvokeAsync<TranspilerResult>(
219219
"./Node/transpile",
220220
pathOfSomeFileToBeTranspiled);
221221
```
@@ -226,7 +226,7 @@ var result = await myNodeServicesInstance.Invoke<TranspilerResult>(
226226
public class TranspilerResult
227227
{
228228
public string Code { get; set; }
229-
public string[] Warnings { get; set;
229+
public string[] Warnings { get; set; }
230230
}
231231
```
232232

@@ -245,7 +245,7 @@ module.exports = function (callback, filePath) {
245245
**Example 2: Getting a stream of binary data from Node**
246246

247247
```csharp
248-
var imageStream = await myNodeServicesInstance.Invoke<Stream>(
248+
var imageStream = await myNodeServicesInstance.InvokeAsync<Stream>(
249249
"./Node/resizeImage",
250250
fullImagePath,
251251
width,
@@ -287,19 +287,19 @@ There's a working image resizing example following this approach [here](https://
287287
**Signature**
288288

289289
```csharp
290-
InvokeExport<T>(string moduleName, string exportName, params object[] args)
290+
InvokeExportAsync<T>(string moduleName, string exportName, params object[] args)
291291
```
292292

293-
This is exactly the same as `Invoke<T>`, except that it also takes an `exportName` parameter. You can use this if you want your JavaScript module to export more than one function.
293+
This is exactly the same as `InvokeAsync<T>`, except that it also takes an `exportName` parameter. You can use this if you want your JavaScript module to export more than one function.
294294

295295
**Example**
296296

297297
```csharp
298-
var someString = await myNodeServicesInstance.Invoke<string>(
298+
var someString = await myNodeServicesInstance.InvokeExportAsync<string>(
299299
"./Node/myNodeApis",
300300
"getMeAString");
301301

302-
var someStringInFrench = await myNodeServicesInstance.Invoke<string>(
302+
var someStringInFrench = await myNodeServicesInstance.InvokeExportAsync<string>(
303303
"./Node/myNodeApis",
304304
"convertLanguage"
305305
someString,
@@ -325,7 +325,7 @@ module.exports = {
325325
};
326326
```
327327

328-
**Parameters, return type, etc.** For all other details, see the docs for [`Invoke<T>`](#invoket)
328+
**Parameters, return type, etc.** For all other details, see the docs for [`InvokeAsync<T>`](#invokeasynct)
329329

330330
## Hosting models
331331

0 commit comments

Comments
 (0)