deasynchronization
This commit is contained in:
parent
b34571c800
commit
d7dbe078dc
17
index.js
17
index.js
|
@ -2,14 +2,21 @@ if (typeof Buffer === 'undefined') {
|
|||
global.Buffer = require('buffer').Buffer
|
||||
}
|
||||
|
||||
var deasync = require('deasync');
|
||||
|
||||
var {
|
||||
RNRandomBytes
|
||||
} = require('react-native').NativeModules
|
||||
RNRandomBytes
|
||||
} = require('react-native').NativeModules;
|
||||
|
||||
export default function randomBytes (length, cb) {
|
||||
if (!cb) throw new Error('synchronous API not supported')
|
||||
export default function randomBytes(length, cb) {
|
||||
if (!cb) {
|
||||
// throw new Error('synchronous API not supported')
|
||||
var exec = deasync(RNRandomBytes.randomBytes);
|
||||
var base64String = exec(length);
|
||||
return new Buffer(base64String, 'base64');
|
||||
}
|
||||
|
||||
RNRandomBytes.randomBytes(length, function (err, base64String) {
|
||||
RNRandomBytes.randomBytes(length, function(err, base64String) {
|
||||
if (err) cb(err)
|
||||
else cb(null, new Buffer(base64String, 'base64'))
|
||||
})
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"ios"
|
||||
],
|
||||
"dependencies": {
|
||||
"buffer": "^3.5.2"
|
||||
"buffer": "^3.5.2",
|
||||
"deasync": "^0.1.4"
|
||||
},
|
||||
"author": "Mark Vayngrib <mark.vayngrib@lablz.com> (http://github.com/mvayngrib)",
|
||||
"license": "ISC"
|
||||
|
|
Loading…
Reference in New Issue