Skip to content

Commit 38a1e73

Browse files
cancerberoSgxjoeferner
authored andcommitted
typos and promisify implementation
1 parent 3f20aec commit 38a1e73

1 file changed

Lines changed: 25 additions & 23 deletions

File tree

README.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ try {
237237

238238
### AsyncOptions: control over the generation of sync, async & promise method variants.
239239

240-
As of release 0.4.5 it became possible to create async methods that return promises by setting the asyncOptions property of the java object. With release 0.4.7 this feature is extended to allow changing the suffix assigned for sync and async method variants, and to further configure this module to optionally omit generation of any of these variants.
240+
As of release 0.4.5 it became possible to create async methods that return promises by setting the `asyncOptions` property of the java object. With release 0.4.7 this feature is extended to allow changing the suffix assigned for sync and async method variants, and to further configure this module to optionally omit generation of any of these variants.
241241

242242
Example:
243243

@@ -247,7 +247,7 @@ java.asyncOptions = {
247247
asyncSuffix: undefined, // Don't generate node-style methods taking callbacks
248248
syncSuffix: "", // Sync methods use the base name(!!)
249249
promiseSuffix: "Promise", // Generate methods returning promises, using the suffix Promise.
250-
promisify: require("when/node").lift
250+
promisify: require('util').promisify // Needs Node.js version 8 or greater, see comment below
251251
};
252252
java.classpath.push("commons-lang3-3.1.jar");
253253
java.classpath.push("commons-io.jar");
@@ -261,9 +261,11 @@ java.newInstancePromise("java.util.ArrayList")
261261
```
262262

263263
#### NOTES:
264+
264265
* If you want the defacto standard behavior, simply don't set java.asyncOptions.
265266
* If you do provide asyncOptions, be aware that this module will not generate method variants of a given flavor if you don't provide a string value for the corresponding suffix (`asyncSuffix`, `syncSuffix`, `promiseSuffix`). In the example above, the application is configured to omit the method variants using node-style async callback functions.
266267
* If you provide `asyncOptions.promiseSuffix` then you must also set `asyncOptions.promisify` to a function that *promisifies* a node-style async function. I.e. the provided function must take as input a function whose last argument is a node callback function, and it must return an equivalent promise-returning function. Several Promises/A+ libraries provide such functions, but it may be necessary to provide a wrapper function. See `testHelpers.js` for an example.
268+
* For `promisify` implementation, if you are using Node.js version 8.0.0 or newer then `promisify: require('util').promisify` will work out of the box. If you need to support and older Node.js version then an implementation needs to be provided, for example, `promisify: require("when/node").lift`
267269
* If you provide `asyncOptions.promisify` then you must provide a *non-empty* string for `asyncOptions.promiseSuffix`.
268270
* Either (but not both) `asyncSuffix` or `syncSuffix` can be the empty string. If you want the defacto standard behavior for no suffix on async methods, you must provide an empty string for `asyncSuffix`.
269271
* We've tested promises with five Promises/A+ implementations. See `testHelpers.js` for more information.
@@ -376,7 +378,7 @@ Loads the class given by className such that it acts and feels like a javascript
376378

377379
__Arguments__
378380

379-
* className - The name of the class to create. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
381+
* className - The name of the class to create. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
380382

381383
__Example__
382384

@@ -395,12 +397,12 @@ __Example__
395397

396398
**java.newInstanceSync(className, [args...]) : result**
397399

398-
Creates an instance of the specified class. If you are using the sync method an exception will be throw if an error occures,
400+
Creates an instance of the specified class. If you are using the sync method an exception will be throw if an error occurs,
399401
otherwise it will be the first argument in the callback.
400402

401403
__Arguments__
402404

403-
* className - The name of the class to create. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
405+
* className - The name of the class to create. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
404406
* callback(err, item) - Callback to be called when the class is created.
405407

406408
__Example__
@@ -437,12 +439,12 @@ __Example__
437439

438440
**java.callStaticMethodSync(className, methodName, [args...]) : result**
439441

440-
Calls a static method on the specified class. If you are using the sync method an exception will be throw if an error occures,
442+
Calls a static method on the specified class. If you are using the sync method an exception will be throw if an error occurs,
441443
otherwise it will be the first argument in the callback.
442444

443445
__Arguments__
444446

445-
* className - The name of the class to call the method on. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
447+
* className - The name of the class to call the method on. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
446448
* methodName - The name of the method to call. The method name can include the full signature (see [Getting the full method signature](#getFullMethodSignature)).
447449
* callback(err, item) - Callback to be called when the class is created.
448450

@@ -461,7 +463,7 @@ __Example__
461463

462464
**java.callMethodSync(instance, methodName, [args...]) : result**
463465

464-
Calls a method on the specified instance. If you are using the sync method an exception will be throw if an error occures,
466+
Calls a method on the specified instance. If you are using the sync method an exception will be throw if an error occurs,
465467
otherwise it will be the first argument in the callback.
466468

467469
__Arguments__
@@ -489,7 +491,7 @@ Gets a static field value from the specified class.
489491

490492
__Arguments__
491493

492-
* className - The name of the class to get the value from. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
494+
* className - The name of the class to get the value from. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
493495
* fieldName - The name of the field to get the value from.
494496

495497
__Example__
@@ -504,7 +506,7 @@ Sets a static field value on the specified class.
504506

505507
__Arguments__
506508

507-
* className - The name of the class to set the value on. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
509+
* className - The name of the class to set the value on. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
508510
* fieldName - The name of the field to set the value on.
509511
* newValue - The new value to assign to the field.
510512

@@ -520,8 +522,8 @@ Creates a new java array of type class.
520522

521523
__Arguments__
522524

523-
* className - The name of the type of array elements. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
524-
* values - A javascript array of values to assign to the java array.
525+
* className - The name of the type of array elements. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
526+
* values - A JavaScript array of values to assign to the java array.
525527

526528
__Example__
527529

@@ -531,7 +533,7 @@ __Example__
531533

532534
*java.newByte(val)**
533535

534-
Creates a new java byte. This is needed because javascript does not have the concept of a byte.
536+
Creates a new java byte. This is needed because JavaScript does not have the concept of a byte.
535537

536538
__Arguments__
537539

@@ -545,7 +547,7 @@ __Example__
545547

546548
*java.newShort(val)**
547549

548-
Creates a new java short. This is needed because javascript does not have the concept of a short.
550+
Creates a new java short. This is needed because JavaScript does not have the concept of a short.
549551

550552
__Arguments__
551553

@@ -559,7 +561,7 @@ __Example__
559561

560562
*java.newLong(val)**
561563

562-
Creates a new java long. This is needed because javascript does not have the concept of a long.
564+
Creates a new java long. This is needed because JavaScript does not have the concept of a long.
563565

564566
__Arguments__
565567

@@ -573,7 +575,7 @@ __Example__
573575

574576
*java.newChar(val)**
575577

576-
Creates a new java char. This is needed because javascript does not have the concept of a char.
578+
Creates a new java char. This is needed because JavaScript does not have the concept of a char.
577579

578580
__Arguments__
579581

@@ -587,7 +589,7 @@ __Example__
587589

588590
*java.newDouble(val)**
589591

590-
Creates a new java double. This is needed to force javascript's number to a double to call some methods.
592+
Creates a new java double. This is needed to force JavaScript's number to a double to call some methods.
591593

592594
__Arguments__
593595

@@ -601,7 +603,7 @@ __Example__
601603

602604
*java.newFloat(val)**
603605

604-
Creates a new java float. This is needed to force javascript's number to a float to call some methods.
606+
Creates a new java float. This is needed to force JavaScript's number to a float to call some methods.
605607

606608
__Arguments__
607609

@@ -622,7 +624,7 @@ garbage collection.
622624

623625
__Arguments__
624626

625-
* interfaceName - The name of the interface to proxy. For nested classes seperate using a '$' (eg. com.nearinfinty.MyClass$NestedClass)
627+
* interfaceName - The name of the interface to proxy. Separate nested classes using `'$'` (eg. `com.nearinfinty.MyClass$NestedClass`).
626628
* functions - A hash of functions matching the function in the interface.
627629

628630
__Example__
@@ -770,9 +772,9 @@ ShutdownHookHelper.setShutdownHookSync(java.newProxy('java.lang.Runnable', {
770772

771773
When you call a Java method through node-java, any arguments (V8/JavaScript objects) will be converted to Java objects on the v8 main thread via a call to v8ToJava (found in utils.cpp). The JavaScript object is not held on to and can be garbage collected by v8. If this is an async call, the reference count on the Java objects will be incremented. The Java method will be invoked in a node.js async thread (see uv_queue_work). When the method returns, the resulting object will be returned to the main v8 thread and converted to JavaScript objects via a call to javaToV8 and the Java object's reference count will then be decremented to allow for garbage collection. The resulting v8 object will then be returned to the callers callback function.
772774

773-
# Static member name conficts ('name', 'arguments', 'caller')
775+
# Static member name conflicts ('name', 'arguments', 'caller')
774776

775-
The Javscript object returned by `java.import(classname)` is a Javascript constructor Function, implemented such that you can create instances of the Java class. For example:
777+
The JavaScript object returned by `java.import(classname)` is a Javascript constructor Function, implemented such that you can create instances of the Java class. For example:
776778

777779
```javascript
778780
var Test = java.import('Test');
@@ -801,7 +803,7 @@ Test.caller(function(err, result) { ... }); // ERROR
801803
var value = Test.NestedEnum.name; // ERROR
802804
```
803805

804-
Node-java can't create those properties, so the above code won't work. Instead, node-java appends a suffix to the name. The default suffix is simpy an underscore `_`, but you can change the suffix using asyncOptions:
806+
Node-java can't create those properties, so the above code won't work. Instead, node-java appends a suffix to the name. The default suffix is simply an underscore `_`, but you can change the suffix using `asyncOptions`:
805807

806808
```javascript
807809
var java = require('java');
@@ -821,7 +823,7 @@ var value = Test.NestedEnum.name_alt; // OK
821823

822824
## Error: Cannot find module '../build/jvm_dll_path.json'
823825

824-
Either postInstall.js didn't run or there was a problem detecting java. Try running postInstall.js manually.
826+
Either `postInstall.js` didn't run or there was a problem detecting java. Try running `postInstall.js` manually.
825827

826828
## Debugging
827829

0 commit comments

Comments
 (0)