Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9314239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:05:23+00:00 2026-06-19T02:05:23+00:00

I am using a function from third party code, which looks like this: scala>

  • 0

I am using a function from third party code, which looks like this:

scala> def willCallback(fun: Function1[Int, Unit]) {
     | doWork()
     | fun(1)
     | }
willCallback: (fun: Int => Unit)Unit

In my code, I define a function and would like it to return the callback function parameter, to achieve this:

scala> def callbackResult():Int = {
     |   willCallback( (i:Int) => {
     |     // What do I put here 
     |     // to make the return value of callbackResult to be i?
     |   })
     | }

What can I do to make it work?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:05:24+00:00Added an answer on June 19, 2026 at 2:05 am

    From your comment it seems that you want willCallback to block until the callback has executed. Here’s how you can do it with the Future/Promise API in Scala 2.10,

    import scala.concurrent._
    
    // Library code (which you can't modify)
    def willCallback(fun: Int => Unit) { fun(1) }
    
    // Your code. You can fulfill a `promise` in your callback
    def callbackResult(): Int = {
      val p = promise[Int]
      val f = p.future
    
      willCallback { i: Int =>
        p.success(i)
      }
    
      // Block until the promise has been fulfilled (the callback has executed).
      // In this case, the return value is 1
      Await.result(f, duration.Duration.Inf)
    }
    

    Of course, there is the danger that if the callback never executes, your callbackResult() method will hang indefinitely. To avoid this danger, it might be better for callbackResult() to return f: Future[Int] rather than await its Int value, as Régis Jean-Gilles suggests.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i am using this Page.ClientScript.RegisterStartupScript() to call a javascript function from vb code
I have this code to pull down a news feed from a third party
*NOTE - This code is from a third party extension. I had no part
I am using this function to list items from table helps depending on parameters:
I'm running a third party script by using a wrapper class I've written which
I have a load of XSLT from a third party which i need to
Java newbie here. I am using a third party library which gives me a
I am using a third-party shopping cart from http://simplecartjs.com/ . For a normal checkout
We are using a third-party COM API from NET. Currently Visual Studio & presumably
I am creating screenshots under Windows and using the LockBits function from GDI+ to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.