• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Nashorn - invoking a callback function from Java

 
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic