shared struct Visit {
value = 0;
}
const visit = new Visit()
assertThrows( () => visit.value = 1 ); // hata - paylaşılan hafızaya yazma
assertThrows( () => visit.value ); // hata - paylaşılan hafızadan okuma
unsafe {
visit.value = 1; // hata yok
visit.value; // hata yok
}
function incrementVisitors() {
// thread safe update,
unsafe {
using lock = Atomics.Mutex.lock(mutex)
visitor.value++;
}
}
javascipt gibi görünmüyor dimi? ama bu gerçek javascript. Ecmascript
in ileri sürümleri için sunulan tekliflerden biri go ve rust gibi dillerle uyumlu hale getirmek. struct, unsafe, atomics, ve mutex gibi kavramlar var. Büyük olasılıkla 1 - 2 sene içindeki ecmascript sürümlerine gelebilir.
Detaylı incelemek isteyen varsa ilgili linkleri bıraktım
https://tc39.es/proposal-structs
https://github.com/tc39/proposal-structs
sunulan diğer teklifler
https://github.com/tc39/proposals