Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

addSingletonFactory is broken #7

Closed
nsk-mironov opened this issue Aug 10, 2015 · 2 comments
Closed

addSingletonFactory is broken #7

nsk-mironov opened this issue Aug 10, 2015 · 2 comments
Assignees
Labels

Comments

@nsk-mironov
Copy link

public class Singleton(val count: Int) {
  init {
    println("not really a singleton $count")
  }
}

public class Magic() {
  public val first: Singleton by Delegates.injectValue()
  public val second: Singleton by Delegates.injectValue()
  public val third: Singleton by Delegates.injectValue()
}

public object Hello : InjektMain() {
  override fun InjektRegistrar.registerInjectables() {
    val counter = AtomicInteger()

    addSingletonFactory {
      Singleton(counter.incrementAndGet())
    }
  }

  platformStatic public fun main(args: Array<String>) {
    val test = Magic()

    println("first ${test.first.count}")
    println("second ${test.second.count}")
    println("third ${test.third.count}")
  }
}

Output:

not really a singleton 1
not really a singleton 2
not really a singleton 3
first 1
second 1
third 1
@nsk-mironov nsk-mironov changed the title addSingletonFactory is broken addSingletonFactory is broken Aug 10, 2015
@apatrida apatrida added the bug label Aug 11, 2015
@apatrida apatrida self-assigned this Aug 11, 2015
@apatrida
Copy link
Contributor

Thanks, problem with the concurrentGetOrPut taken from Kara is broken, quick fix coming.

apatrida added a commit that referenced this issue Aug 11, 2015
…erfectly thread safe because computeGetOrPut missing in JDK 7
@apatrida
Copy link
Contributor

Fixed in v 1.1.1 - releasing to maven central.

I will also release 1.1.1-JDK8 which uses a safe concurrentGetOrPut. And the registry based on Guava coming soon is also safe.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants