Comments (9)
Hi Vladimir,
Server side async functions are 100% supported.
Simply pass in a callback.The tricky part is you must also pass in a 2nd callback for the return value.
Here is an example
Server:
var everyone = require("now").initialize(httpServer);
everyone.now.getServerInfo = function(callback){
doAsync(function(data){
callback(data);
});
}
Client:
now.getServerInfo(function(data){
// this is the callback of the async function
}, function(returnVal){
// this contains the return value, which will be undefined since the server function doesn't return anything.
});
from now.
Very well. Thanks!
from now.
I tried this and it does not seem to work.
from now.
It does work for me.
server:
everyone.now.getServerInfo = function(arg, callback){
callback('Hello from ' + arg);
}
client:
now.getServerInfo('async function', function(result){
console.log(result); // 'Hello from async function'
},function(){});
Notice the noop second parameter
from now.
Hi guys,
In yesterday's release (v0.3) we have decided to eliminate the necessity of the noop second parameter that dvv has shown. This is because return
values are no longer supported. Instead async callbacks should be used.
Considering server code:
everyone.now.getServerInfo = function(callback){
callback('Hello');
return "Bye";
}
And client code:
In v0.2 you could do this (this is no longer valid in the latest release):
now.getServerInfo(function(data){
// data contains 'Hello'
}, function(returnVal){
// this contains 'Bye'
});
But v0.3 this must be changed to
now.getServerInfo(function(data){
// data contains 'Hello'
});
As you can see this gets rid of the confusing noop callback that you would have to use in v0.2. Originally that was used for return values from the server function, but we found people rarely used return values so we decided to eliminate the confusing element in v0.3
from now.
Very well.
from now.
0.3: now.getServerInfo(console.log)
throws 'Illegal invocation'. So one can not use natives as callback?
from now.
@dvv, yes this is a known issue. It's not possible to do nativeFunction.apply(...) as that throws the illegal invocation
from now.
np
from now.
Related Issues (20)
- installation fail :( HOT 3
- Can not read the property of 'ressource' undefined HOT 1
- No dev in six months. What is the future of NowJS? HOT 13
- Now module Installation failed ..... throwing error in windows
- npm install now ..... throwing error HOT 1
- Not working with Dojo due to Socket.io-client
- Implementing chat module by using Nowjs HOT 6
- now.js and node autocluster core module
- Issue in limit of sending message in chat
- /nowjs/now.js ??
- website HOT 7
- Connecting to nodejs on http from https site HOT 1
- cannot finde module '../build/Release/nodeproxy.node'
- iOS app crashed in release mode while using Nowjs library
- Now doesn't work with latest sockets.io HOT 2
- Does not work with angular-cli: content.charCodeAt is not a function
- possible spam HOT 1
- Error: Cannot find module 'now' HOT 3
- Error: Cannot find module 'now'
- http://www.nowjs.com is not correct HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from now.