• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nashorn - invoking a callback function from Java

 
Ron McLeod
Bartender
Pie
Posts: 1027
64
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just starting working with Nashorn and things have been working well until I tried to make a asynchronous service - implmented in Java and called from a script.  My service receives a script function  which is to be called-back sometime later.  The function passed to my service is an anonymous function, and I can't figure-out how it can be called from Java.

I've spent an hour or so poking around at this, and I can see anyway to do it -- most likely my approach is wrong and I should be looking at doing this differently.  Any suggestions?

default.jstimerTest.js
Console output

 
Ron McLeod
Bartender
Pie
Posts: 1027
64
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Working now - I exposed Runnable to the scripting environment and modified the TimerService#startTimer to take a Runnable for the timer handler rather than a script function.

default.jstimerTest.js
Console output

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic